Fine_Observer Posted July 29, 2006 Share Posted July 29, 2006 Greetings. I trying to make a script so the ordinary user login can open the restrited GPO network properties. Oddly, even with RunAsSet, it didn't works. It only work if I elevates the user privilleges to Administrator. Here's the script: $ProfileDir=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") For $i= 1 to 10 $UserProfileSID= RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", $i) If @error <> 0 then ExitLoop $SIDSub="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $UserProfileSID $UserProfileDir=RegRead($SIDSub,"ProfileImagePath") $UserProfile=StringReplace($UserProfileDir,$ProfileDir & "\","") If $UserProfile = @UserName Then ExitLoop Next RunAsSet("administrator",@computername,"password") RegDelete("HKEY_USERS\" & $UserProfileSID & "\Software\Policies\Microsoft\Windows\Network Connections") RunAsSet() I'm using AutoIT v3.1.1.132 (beta) Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 29, 2006 Share Posted July 29, 2006 Greetings. I trying to make a script so the ordinary user login can open the restrited GPO network properties. Oddly, even with RunAsSet, it didn't works. It only work if I elevates the user privilleges to Administrator. Here's the script: RunAsSet("administrator",@computername,"password") RegDelete("HKEY_USERS\" & $UserProfileSID & "\Software\Policies\Microsoft\Windows\Network Connections") RunAsSet() I'm using AutoIT v3.1.1.132 (beta) Read the help file on RunAsSet(). The credential given apply to CMD shells created by Run() and RunWait(), not to AutoIT functions in the same script. You need to put your registry function in a seperate script and call that script with Run() or RunWait() after setting the credentials with RunAsSet(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Helge Posted July 29, 2006 Share Posted July 29, 2006 (edited) Read the help file on RunAsSet(). The credential given apply to CMD shells created by Run() and RunWait(), not to AutoIT functions in the same script. You need to put your registry function in a seperate script and call that script with Run() or RunWait() after setting the credentials with RunAsSet(). ..or just make the script call itself with command line parameters. Edited July 29, 2006 by Helge Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 29, 2006 Share Posted July 29, 2006 ..or just make the script call itself with command line parameters. True enough. I guess it should also be said for stict accuracy that it doesn't have to be a script. If the function can be accomplished by a single commad line string, like using REG.EXE: $ExtCmd = 'REG.EXE QUERY "HKEY_USERS\' & $UserProfileSID & '\Software\Policies\Microsoft\Windows\Network Connections"' RunAsSet("administrator",@computername,"password") $RetCode = RunWait($ExtCmd) RunAsSet() Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Fine_Observer Posted July 30, 2006 Author Share Posted July 30, 2006 True enough. I guess it should also be said for stict accuracy that it doesn't have to be a script. If the function can be accomplished by a single commad line string, like using REG.EXE: $ExtCmd = 'REG.EXE QUERY "HKEY_USERS\' & $UserProfileSID & '\Software\Policies\Microsoft\Windows\Network Connections"' RunAsSet("administrator",@computername,"password") $RetCode = RunWait($ExtCmd) RunAsSet() Unfortunately, the built-in registry editor is already restricted by GPO too... Curiously, I'm trying to run this compiled script with command line's runas (get a rid RunAsSet, off course). It's still didn't work. With another registry editor, it work flawlesly. Any comment? But I will try you sugestion and notify you soon. Thanks! Link to comment Share on other sites More sharing options...
Fine_Observer Posted July 30, 2006 Author Share Posted July 30, 2006 It's still doesn't work. I modified previous script with this: If $CmdLineRaw="admin" Then RunAsSet("Administrator",@ComputerName,"password") RunWait("net-unhook.exe") RunAsSet() Else Call ("_Main") EndIf Func _Main() $ProfileDir=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") For $i= 1 to 10 $UserProfileSID= RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", $i) If @error <> 0 then ExitLoop $SIDSub="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $UserProfileSID $UserProfileDir=RegRead($SIDSub,"ProfileImagePath") $UserProfile=StringReplace($UserProfileDir,$ProfileDir & "\","") If $UserProfile = @UserName Then ExitLoop Next ;RegDelete("HKEY_USERS\" & $UserProfileSID & "\Software\Policies\Microsoft\Windows\Network Connections") $Reg='REG DELETE "HKEY_USERS\' & $UserProfileSID & '\Software\Policies\Microsoft\Windows\Network Connections"' RunWait($Reg) EndFunc You can see, I already trying the ReqDelete and Reg methods, but none of them are works. Sorry for this trouble. Link to comment Share on other sites More sharing options...
/dev/null Posted July 30, 2006 Share Posted July 30, 2006 It's still doesn't work. I modified previous script with this:Thy THISCheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Fine_Observer Posted July 31, 2006 Author Share Posted July 31, 2006 Thy THISCheersKurtStill now working. What makes me more curious is that why even runas doesn't work with this script. I already checking it with another PC and the result is still the same unless I elevate the account privilleges to administrator. Is this some kind of bug? Link to comment Share on other sites More sharing options...
MHz Posted July 31, 2006 Share Posted July 31, 2006 You have 2 main conditions in your last script. To Run net-unhook.exe as admin or to use registry functions not as admin. I cannot edit your code as the 2 conditions seem unbalanced to perhaps both need to be an admin operation. Link to comment Share on other sites More sharing options...
Fine_Observer Posted July 31, 2006 Author Share Posted July 31, 2006 Net-unhook.exe is an exe compiled version of this script. Basically I trying to run the script itself with "admin" as second parameter to because I don't want run two different script just for Administrator privellege as Helge and PsaltyDS. This two conditions is needed to prevent multiple RunAsSet execution. Does anyone have similar experience even with Window's runas when running AutoIT compiled script? Link to comment Share on other sites More sharing options...
Lazycat Posted July 31, 2006 Share Posted July 31, 2006 Not tried this myself, but maybe this script will help you?http://www.autoitscript.com/forum/index.php?showtopic=14710 Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
MHz Posted July 31, 2006 Share Posted July 31, 2006 Net-unhook.exe is an exe compiled version of this script. Basically I trying to run the script itself with "admin" as second parameter to because I don't want run two different script just for Administrator privellege as Helge and PsaltyDS. This two conditions is needed to prevent multiple RunAsSet execution. Does anyone have similar experience even with Window's runas when running AutoIT compiled script?OK, I will swap the check method around for incoming parameters and also add the admin switch to the RunWait function. Try this If $CMDLINE[0] And $CMDLINE[1] = "admin" Then ; Admin _Main() Else ; Not Admin RunAsSet("Administrator",@ComputerName,"password") RunWait("net-unhook.exe admin") RunAsSet() Exit EndIf Func _Main() $ProfileDir=RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") For $i= 1 to 10 $UserProfileSID= RegEnumKey("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", $i) If @error <> 0 then ExitLoop $SIDSub="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $UserProfileSID $UserProfileDir=RegRead($SIDSub,"ProfileImagePath") $UserProfile=StringReplace($UserProfileDir,$ProfileDir & "\","") If $UserProfile = @UserName Then ExitLoop Next ;RegDelete("HKEY_USERS\" & $UserProfileSID & "\Software\Policies\Microsoft\Windows\Network Connections") $Reg='REG DELETE "HKEY_USERS\' & $UserProfileSID & '\Software\Policies\Microsoft\Windows\Network Connections"' RunWait($Reg) EndFunc Link to comment Share on other sites More sharing options...
/dev/null Posted July 31, 2006 Share Posted July 31, 2006 Still now working. What makes me more curious is that why even runas doesn't work with this script. I already checking it with another PC and the result is still the same unless I elevate the account privilleges to administrator. Is this some kind of bug?no bug, works fine. Post you code, so we can see what's going wrong...CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Fine_Observer Posted August 1, 2006 Author Share Posted August 1, 2006 (edited) Sorry Mhz, the result it's still the same. Kurt, it's should be like this, right? expandcollapse popup global $username = "YOUR NAME HERE"; <<=== change THIS !! global $domainname = @Computername; <<=== change THIS !! global $password = "YOUR PASSWORD HERE"; <<=== change THIS !! global $started_with_runas = 0 ;****************************************************** ;** Check commandline params ;****************************************************** if $CmdLine[0] > 0 then for $n = 1 to $cmdline[0] step 1 select case $cmdline[$n] = "/ra" $started_with_runas = 1 endselect next else ;****************************************************** ;** If script was started without params restart it with ;** RUnAsSet ;****************************************************** RunAsSet( $username , $domainname, $password) Run(@ScriptDir & "\" & @ScriptName & " /ra", @WorkingDir) exit endif ;****************************************************** ;** Exit if script was not started with /ra ;****************************************************** if $started_with_runas = 0 then exit endif ;------------------------------------------------------------- ;- Your "privileged" Code HERE ;------------------------------------------------------------- $ProfileDir=RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") For $i= 1 to 10 $UserProfileSID= RegEnumKey("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList", $i) If @error <> 0 then ExitLoop $SIDSub="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" & $UserProfileSID $UserProfileDir=RegRead($SIDSub,"ProfileImagePath") $UserProfile=StringReplace($UserProfileDir,$ProfileDir & "\","") If $UserProfile = @UserName Then ExitLoop Next RegDelete("HKEY_USERS\" & $UserProfileSID & "\Software\Policies\Microsoft\Windows\Network Connections") ;$Reg='REG DELETE "HKEY_USERS\' & $UserProfileSID & '\Software\Policies\Microsoft\Windows\Network Connections"' ;RunWait($Reg) [code=auto:0] Sorry about the bug statement. But when the code really did it's job under all user's logon with administrator privilleges, how can posibbly go wrong when you use RunAsSet or even runas (right click or command line version)? Edited August 1, 2006 by Fine_Observer Link to comment Share on other sites More sharing options... /dev/null Posted August 1, 2006 /dev/null MVPs 2.9k 1 Share Posted August 1, 2006 Sorry Mhz, the result it's still the same.Kurt, it's should be like this, right?right. Two things:1.) Did you change the marked things "change THIS !!" ?2.) Did you run your script with the parameter "/ra" (run as). Only then it will run with the right of the given user.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options... Fine_Observer Posted August 2, 2006 Fine_Observer Members 10 Author Share Posted August 2, 2006 right. Two things:1.) Did you change the marked things "change THIS !!" ?2.) Did you run your script with the parameter "/ra" (run as). Only then it will run with the right of the given user.CheersKurtI did and still doesn't work. Link to comment Share on other sites More sharing options... /dev/null Posted August 2, 2006 /dev/null MVPs 2.9k 1 Share Posted August 2, 2006 I did and still doesn't work. put a msgbox before your code to check the userid. What's the output? ;------------------------------------------------------------- ;- Your "privileged" Code HERE ;------------------------------------------------------------- msgbox(4096,"User",@UserName) If it's the correct user, then that user has not enough rights to change the registry. BTW: This won't work when run with runasset(): If $UserProfile = @UserName Then ExitLoop @Username will be the name of the new user! Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Briegel Posted August 2, 2006 Share Posted August 2, 2006 RunAsSet("Administrator",@ComputerName,"password") Did you try to run the script as local admin? ....unless I elevate the account privilleges to administratorHow did you do this? Set local account into local admins, set domain user into local admins or domain user into global group and global group into local admins? Link to comment Share on other sites More sharing options...
Fine_Observer Posted August 2, 2006 Author Share Posted August 2, 2006 Okay, okay... (wow, this is going to heat up a little bit...). I use 2 user account for testing, a local user account and a domain user account. I ran the script on both account and only works when I set them to local admin privillges. For RunAsSet (and runas), I use the Administrator on local. Link to comment Share on other sites More sharing options...
/dev/null Posted August 2, 2006 Share Posted August 2, 2006 For RunAsSet (and runas), I use the Administrator on local.As I told you, your script logic will not work when run with runasset(). As far as I can see your trying to delete the network connections of the user that runs the script. Your check " If $UserProfile = @UserName Then ExitLoop" will fail if the script is run with runasset()!! You need another logic.Start the script without runasset(). Retrieve the user name of the current user (@Username). Then rerun the script with runasset() AND give it the username on the command line (script.exe /ra /user:test). Then you can figure out the SID of the user and delete the connection entries with admin privileges.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now