vovo Posted June 12, 2008 Share Posted June 12, 2008 Hi All, I cannot using RunAs() install printer. Somebody help me? ;; Run as Admin User ; Fill in the username and password appropriate for your system. Local $sUserName = "Administrator" Local $sPassword = "colorlife" ; Run a command prompt as the other user. RunAs($sUserName, @ComputerName, $sPassword, 0, @ComSpec, @SystemDir) ;; Stop the Print Spooler service RunWait('cmd /c net stop "print spooler"') ;; Right the Registry Values for the IP port RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "Protocol", "REG_DWORD", "00000001") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "Version", "REG_DWORD", "00000001") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "HostName", "REG_SZ", "") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "HWAddress", "REG_SZ", "") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "IPAddress", "REG_SZ", "192.168.5.59") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "PortNumber", "REG_DWORD", "00009100") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "SNMP Community", "REG_SZ", "public") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "SNMP Enabled", "REG_DWORD", "00000001") RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.5.59", "SNMP Index", "REG_DWORD", "00000001") ;; Start the Print Spooler Service RunWait('cmd /c net start "print spooler"') ;; Install the printer RunWait(@ComSpec & ' /c rundll32 printui.dll,PrintUIEntry /if /b "IBM Printer" /f %windir%\inf\ntprint.inf /r "IP_192.168.5.59" /m "HP LaserJet 4L" /Z') Link to comment Share on other sites More sharing options...
TurionAltec Posted June 12, 2008 Share Posted June 12, 2008 Runas will launch another process with the given credentials, it will not change the credentials of script calling it. In your example "@comspec" (command prompt) will be run with admin credentials, but not the rest of the script. So use the original script as a helper script to start a main script as admin, eg in your launcher script: RunAs($sUserName, @ComputerName, $sPassword, 0, "mainscript.exe", @ScriptDir)oÝ÷ Û^é{®*m{¢{Z{-êÞ²Ú¶¡×¯*.ßÙe綬y§jÇèæÊ&©Ý¶±¦XÙr®éÖwhÂÇ(f§vƬiÙ¢+-«h¬Z+{¦¦WºÚ"µÍ[Ê ÌÍÜÕÙ[YKÛÛ][YK ÌÍÜÔÜÝÛÜ ÌÎNØÛYØÈ]Ý ][ÝÜ[ÜÛÛ][ÝÉÌÎNËÞÝ[QB[ÕØZ] ÌÍÜÕÙ[YKÛÛ][YK ÌÍÜÔÜÝÛÜÛÛTÜXÈ [È ÌÎNÈØÈ[Ì[ZK[RQ[HÚYØ ][ÝÒPH[][ÝÈÙ ]Ú[IÌLÚ[ÌLÛ[[Ü ][ÝÒTÌNLMKNI][ÝÈÛH ][ÝÒÙ] ][ÝÈÖÌÎNÊ Windows includes a "REG" command for command line modification of the registry if you wish to go this route. Type "reg /?" at a command prompt for more info. I'd recommend the first option. Link to comment Share on other sites More sharing options...
TurionAltec Posted June 13, 2008 Share Posted June 13, 2008 I saw a better approach to the first method in another post: http://www.autoitscript.com/forum/index.php?showtopic=73291 If your trying to run the compiled script with admin rights, you can use singlelton and make the script call itself with RunAs() again and once loaded the 2nd time close the first instance. Once the script has called itself with runas then any file operations work fine in a limited user account. I recently used the above method myself and it all works great . Cheers ProcessList() Will tell you if the process exists $processlist=ProcessList("autoitscript.exe") If $processlist[0][0] = 1 Then Runaswait("autoitscript.exe") Else RunWait('cmd /c net stop "print spooler"') ;insert your other commands here Endif Or look at the _Singleton UDF: #Include <Misc.au3> _Singleton($sOccurenceName[, $iFlag = 0]) 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