Jump to content

Win7, system protection, and Perl


jeffw_00

Recommended Posts

Hi - This one is baffling me. I'm sure many of you are familiar with protecting your system via the "hosts" file that can be obtained from http://winhelp2002.mvps.org/. So basically, I had written a Perl script (I do all my system admin in Perl) that pulled down the hosts file and updated it in c:\windows\system32\drivers\etc. Worked great in XP. Now i upgraded to windows 7, and the Perl scrip says it can't find the hosts file. But here's what's baffling me....

 

The simple approach, using the .BAT file below works fine. I don't even need to "run from administrator"

-------

ATTRIB +A -H -R -S %windir%\SYSTEM32\DRIVERS\ETC\HOSTS

del /q %windir%\SYSTEM32\DRIVERS\ETC\HOSTS

copy c:\jeff\backups\hosts\masterhosts.txt %windir%\SYSTEM32\DRIVERS\ETC\HOSTS

ATTRIB +A +H +R +S %windir%\SYSTEM32\DRIVERS\ETC\HOSTS

-------------

However, when I issue the SAME commands from my Perl script, it says it cannot find the specified files. Now, if i issue perl commands to "cd %windir%\SYSTEM32\DRIVERS\ETC" it doesn't complain, so it can get to the folder, but it claims it can't find the file.

 

I know it's some sort of funky windows protection issue, and it occurs to me that if I give "Everyone" access to every folder in the tree that might fix it, but that's sort of a blunt-force approach with it's own issues.

 

What I don't get is that the bat. file is effective, but the perl script is not. (even if i call the .bat file from the perl script it doesn't work).

 

Is there some easy workaround? This is a single-account system running Win7 Home Premium.

 

Thanks!

/j

Link to comment
Share on other sites

I don't get a "Run as admin" option when I right click it. And, in actuality, I want to run this from the task scheduler anyway....not sure if there's an option there (or how much weight it carries if it doesn't work interactively).

 

Thanks!

/j

Link to comment
Share on other sites

Hi Lil Bambi - Thanks. I had kinda figured that out. :shifty: What i was asking was how to make my perl script run with Adminstrator privs...

/j

Link to comment
Share on other sites

Does Win7 have the runas command available in the command prompt. My VM is shut down right now, so I can't get to it easily.

 

I know Server 2008 does, at least.

 

Adam

Link to comment
Share on other sites

Guest LilBambi

Runas (in cmd) - TN Blog

 

Syntax:

 

runas [{/profile | /noprofile}] [/env] [{/netonly | /savecred}] [/smartcard] [/showtrustlevels] [/trustlevel] /user:<UserAccountName> "<ProgramName> <PathToProgramFile>"

 

Example:

 

runas /user:<localmachinename>\administrator cmd

 

More examples, and the parameters, remarks, etc. in the TN Blog entry.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...