Steven Vandenhoute Posted December 14, 2006 Posted December 14, 2006 Tried to convert following vbs script to auto it, but can't have any luck.Can anybody see, and tell me what I'm doing wrong?Original code Quote Option Explicit'Declare variablesDim WSHShell, rr, rr2, MyBox, val, val2, ttl, toggleDim jobfunc, itemtypeOn Error Resume NextSet WSHShell = WScript.CreateObject("WScript.Shell")val = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"val2 = "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"itemtype = "REG_DWORD"jobfunc = "Registry Editing Tools are now "ttl = "Result"'reads the registry key value.rr = WSHShell.RegRead (val)rr2 = WSHShell.RegRead (val2)toggle=1If (rr=1 or rr2=1) Then toggle=0If toggle = 1 Then WSHShell.RegWrite val, 1, itemtype WSHShell.RegWrite val2, 1, itemtype Mybox = MsgBox(jobfunc & "disabled.", 4096, ttl)Else WSHShell.RegDelete val WSHShell.RegDelete val2 Mybox = MsgBox(jobfunc & "enabled.", 4096, ttl)End IfCode I created in Auto it Quote ;variablesdim $wshshell,$rr, $rr2, $MyBox, $val, $val2, $ttl, $toggle, $jobfunc, $itemtype$WshShell = ObjCreate("Wscript.Shell")$val="HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"$val2="HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools"$itemtype="REG_DWORD"$ttl="Result";On Error Resume Next;reads the registry key value.$rr = $WSHShell.RegRead ($val)$rr2 = $WSHShell.RegRead ($val2)$toggle=1If ($rr=1 or $rr2=1) Then $toggle=0If $toggle = 1 Then $WSHShell.RegWrite $val, 1, $itemtype $WSHShell.RegWrite $val2, 1, $itemtype $Mybox = MsgBox(0,$jobfunc & "disabled."& $ttl)Else $WSHShell.RegDelete $val $WSHShell.RegDelete $val2 $Mybox = MsgBox(0,$jobfunc & "enabled."& $ttl)EndIfEndIf "You cannot solve a problem with the mind that created it" (Albert Einstein)
CoePSX Posted December 14, 2006 Posted December 14, 2006 Don't use Dim to declare the variables. Dim is to declare arrays with custom dimensions. Just declare them as Global. MsgBox takes three parameters. MsgBox (Flag, Title, Text) When you call functions, use the parentesis: $WSHShell.RegWrite ($val, 1, $itemtype) And there's an extra EndIf down there. [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font]
Locodarwin Posted December 14, 2006 Posted December 14, 2006 (edited) Steven Vandenhoute said: Tried to convert following vbs script to auto it, but can't have any luck.Can anybody see, and tell me what I'm doing wrong?Original codeCode I created in Auto itIn AutoIt, you need to place parentheses around COM method parameters, like this: $WSHShell.RegWrite ($val, 1, $itemtype)-S Edited December 14, 2006 by Locodarwin (Yet Another) ExcelCOM UDF"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly...[indent]...specialization is for insects." - R. A. Heinlein[/indent]
Steven Vandenhoute Posted December 14, 2006 Author Posted December 14, 2006 So I've eddited this a lit but still no works. this is what I have now ;variables Global $wshshell,$rr, $rr2, $MyBox, $val, $val2, $ttl, $toggle, $jobfunc, $itemtype $WshShell = ObjCreate("Wscript.Shell") $val="HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools" $val2="HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableRegistryTools" $itemtype="REG_DWORD" $jobfunc = "Registry Editing Tools are now " $ttl="Result" ;On Error Resume Next ;reads the registry key value. $rr = $WSHShell.RegRead($val) $rr2 = $WSHShell.RegRead($val2) $toggle=1 If ($rr=1 or $rr2=1) Then $toggle=0 If $toggle = 1 Then $WSHShell.RegWrite($val, 1, $itemtype) $WSHShell.RegWrite($val2, 1, $itemtype) $Mybox = MsgBox(0,"Status",$jobfunc & "disabled."& $ttl) Else $WSHShell.RegDelete($val) $WSHShell.RegDelete($val2) $Mybox = MsgBox(0,"Status",$jobfunc & "enabled."& $ttl) EndIf "You cannot solve a problem with the mind that created it" (Albert Einstein)
Gyzmok Posted December 14, 2006 Posted December 14, 2006 In autoit you don't need to use ("Wscript.Shell") to read/write/delete into the registry. See help file for examples : $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir") D2charkeeper = No more 'expired characters' in D2.File Date Changer = Change the file date(s), attributes and the filename case of multiple files @ once.Updater_full = Copy/Update your autoitscripts, pictures, .mp3, .avi etc ... subdirs from your PC to your memory stick or to your external harddisk. Now with scheduling and logging.Questmapper
Steven Vandenhoute Posted December 14, 2006 Author Posted December 14, 2006 I know you can just use regread and regwrite, but what if the register is locked by the system admin? In our company the use of regedit is locked for our users. So, I did a search on the internet, and via the vbs script I can unlock and lock the register. I'm writing a script for our users, and for that I need modifie a few register settings. (for the places bar => see other post of mine) If you have another idea for unlocking register, please share it with me. "You cannot solve a problem with the mind that created it" (Albert Einstein)
Gyzmok Posted December 14, 2006 Posted December 14, 2006 Ok Steven, sorry Maybe if you know the admin password, you can use the second logon function and temporarly logon as admin in your script before you start the registry stuff: (runs only if compiled - because of the input parameter) AutoItSetOption ( "RunErrorsFatal", 0) ; variable definition $username="ADMIN" ; local admin account name $Password="PASSWORD" ; local admin account psw $domain="DOMAIN" $run = 0 ; run indicator 1=first cycle uninstall 2=install new ; retrieve commandline parameter If $CmdLine[0] = 1 then $run = $CmdLine[1] ; If $run = 0 then if isadmin() then $run = 1 else ; *** Changing credentials.. RunAsSet ($Username, $domain, $Password) ; start the script program (itself) again but now in Adminmode...so all done tasks will run in Adminmode Run('"' & @ScriptFullPath & '" " 1"' ) ; if fails then exits because username & password is not correct if @error = 1 then msgbox(48,"Error","cannot start the installation because you are not in Admin mode ") exit endif exit endif EndIf ;do your stuff here ;RunWait("regedit.exe") RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_SZ", "Hello this is a test") D2charkeeper = No more 'expired characters' in D2.File Date Changer = Change the file date(s), attributes and the filename case of multiple files @ once.Updater_full = Copy/Update your autoitscripts, pictures, .mp3, .avi etc ... subdirs from your PC to your memory stick or to your external harddisk. Now with scheduling and logging.Questmapper
ptrex Posted December 14, 2006 Posted December 14, 2006 @steven, There are 2 alternative ways of manipulating the Registry. One is using the WMI object to read an write to the REG. VBscript Example : Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\System Admin Scripting Guide" strValueName = "String Value Name" strValue = "string value" oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue strValueName = "DWORD Value Name" dwValue = 82 oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue This way you can also provide access authority if needed. The other way is using the ObjCreate("VBScript.RegExp") But not sure if the last option is able to write the REG. If you need more info let me know in a PM. Regards / Tot ziens, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
Steven Vandenhoute Posted December 14, 2006 Author Posted December 14, 2006 @Gysmok, a second account is impossible, because I need to write to the local user @Ptrex Isn't there anyway to do it with autoit? @both thx for the replies "You cannot solve a problem with the mind that created it" (Albert Einstein)
ptrex Posted December 14, 2006 Posted December 14, 2006 @steven, This is the VBcriot examole translated into AutotIT : VBscript Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SYSTEM\CurrentControlSet\Services" oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys For Each subkey In arrSubKeys Wscript.Echo subkey Next ;AutoIT script Dim $arrSubKeys Const $HKEY_LOCAL_MACHINE = 0x80000002 $strComputer = "." $oReg=ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & _ $strComputer & "\root\default:StdRegProv") $strKeyPath = "SYSTEM\CurrentControlSet\Services" $oReg.EnumKey ($HKEY_LOCAL_MACHINE, $strKeyPath, $arrSubKeys) For $subkey In $arrSubKeys ConsoleWrite ($subkey&@CR) Next I hope this can help you get started. Otherwise send me a PM. regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
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