jeffw_00 Posted June 28, 2014 Share Posted June 28, 2014 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 Quote Link to comment Share on other sites More sharing options...
ross549 Posted June 28, 2014 Share Posted June 28, 2014 Is the script running as Administrator or user? 1 Quote Link to comment Share on other sites More sharing options...
jeffw_00 Posted June 28, 2014 Author Share Posted June 28, 2014 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 Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 28, 2014 Share Posted June 28, 2014 It does need to be run as Administrator. If you look at the page: Updating the HOSTS file in Windows 7 Quote Link to comment Share on other sites More sharing options...
jeffw_00 Posted June 28, 2014 Author Share Posted June 28, 2014 Hi Lil Bambi - Thanks. I had kinda figured that out. What i was asking was how to make my perl script run with Adminstrator privs... /j Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 28, 2014 Share Posted June 28, 2014 How to elevate Perl process using UAC Get admin access in perl script for Win-7 I was still searching for it when you posted. Quote Link to comment Share on other sites More sharing options...
jeffw_00 Posted June 28, 2014 Author Share Posted June 28, 2014 Thanks - the answer is actually here... https://metacpan.org/pod/Win32::RunAsAdmin Best /j 1 Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 28, 2014 Share Posted June 28, 2014 It was also in the first link, but whatever works. Quote Link to comment Share on other sites More sharing options...
jeffw_00 Posted June 28, 2014 Author Share Posted June 28, 2014 that's how i found it - just making it easier for others by a) direct link confirming it worked Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 28, 2014 Share Posted June 28, 2014 Great! Quote Link to comment Share on other sites More sharing options...
ross549 Posted June 29, 2014 Share Posted June 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
mac Posted June 29, 2014 Share Posted June 29, 2014 On WIN7PRO 64bit. Click on Start, All Programs, Accessories. Right-click on CMD and choose Run as Administrator. 1 Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 29, 2014 Share Posted June 29, 2014 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. Quote Link to comment Share on other sites More sharing options...
jeffw_00 Posted June 29, 2014 Author Share Posted June 29, 2014 hmmm - that might have been easier - thanks! Quote Link to comment Share on other sites More sharing options...
goretsky Posted June 30, 2014 Share Posted June 30, 2014 Hello, Another option might be JoeWare's Create Process as User (CPAU) program, in case you don't want to use RunAs. Regards, Aryeh Goretsky 1 Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 30, 2014 Share Posted June 30, 2014 Hello, Another option might be JoeWare's Create Process as User (CPAU) program, in case you don't want to use RunAs. Regards, Aryeh Goretsky Nice! I wasn't aware of that software! Great find. Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 30, 2014 Share Posted June 30, 2014 (edited) Awesome! Joe's cat looked a lot like the Root cat! And the image name is trouble1 (when the Root Cat would come into the room, we would say, here comes trouble), and Joe calls the cat President and CEO - that is so funny! Great list of free tools too! Edited June 30, 2014 by LilBambi Quote Link to comment Share on other sites More sharing options...
ebrke Posted June 30, 2014 Share Posted June 30, 2014 The Director of Research and Development is cute too. Appears to be a rodent of some type, wonder how it gets along with the CEO. Quote Link to comment Share on other sites More sharing options...
Guest LilBambi Posted June 30, 2014 Share Posted June 30, 2014 Yes, he is! LOL! Quote Link to comment Share on other sites More sharing options...
Temmu Posted July 1, 2014 Share Posted July 1, 2014 what is "cpan?" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.