[ActiveDir] Kix to .vbs
What would be the simplest way to convert this kix scrip to ..vbs? ; If workstation, exit script If @ProductType = Windows 2000 Professional or @ProductType = Windows XP Professional or @ProductType = Windows NT Workstation cls Exit Endif ; Check / Set VNC application hooks for logon.scr screen saver $ReturnCode = KeyExist(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr) If $ReturnCode=0 Addkey(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_Deferral,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_use_GetUpdateRect,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_KeyPress,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_LButtonUp,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_MButtonUp,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_RButtonUp,1,reg_dword) WriteValue(HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr,use_Timer,0,reg_dword) EndIf ; Check / Set registry settings for BGINFO $ReturnCode = KeyExist(HKCU\Software\Winternals) If $ReturnCode = 0 Addkey(HKCU\Software\Winternals) EndIf $ReturnCode = KeyExist(HKCU\Software\Winternals\BGInfo) If $ReturnCode = 0 Addkey(HKCU\Software\Winternals\BGInfo) WriteValue(HKCU\Software\Winternals\BGInfo,Background,0,reg_dword) WriteValue(HKCU\Software\Winternals\BGInfo,Foreground,16777215,reg_dword) EndIf ; Run BGINFO from NetLogon share Run @Ldrive + \bginfo.exe /i\\gsfps\netlogon\newbginfo.bgi /timer:0 ; Check / Set registry settings for screen saver. Logoff user if settings are updated $IsLocked = ReadValue(HKCU\Control Panel\Desktop,ScreenSaverIsSecure) $SSTimeOut = ReadValue(HKCU\Control Panel\Desktop,ScreenSaveTimeout) $SSActive = ReadValue(HKCU\Control Panel\Desktop,ScreenSaveActive) $ScrnSave = ReadValue(HKCU\Control Panel\Desktop,SCRNSAVE.EXE) If $IsLocked = 0 or (VAL($SSTimeOut) 900) or $SSActive = 0 or $ScrnSave = WriteValue(HKCU\Control Panel\Desktop,ScreenSaverIsSecure,1,reg_sz) WriteValue(HKCU\Control Panel\Desktop,ScreenSaveActive,1,reg_sz) WriteValue(HKCU\Control Panel\Desktop,ScreenSaveTimeout,900,reg_sz) WriteValue(HKCU\Control Panel\Desktop,SCRNSAVE.EXE,%system root%\system32\logon.scr,reg_sz) MessageBox(ScreenSaver settings were not previously set. Settings have been updated. A logout is required to activate new settings. Click Ok and the system will logout you out now. Auto-logoff in 20 seconds.,Logout Required,4112,20) Logoff(1) EndIf Devon Harding Windows Systems Engineer Southern Wine Spirits - BSG 954-602-2469 __This message and any attachments are solely for the intended recipientand may contain confidential or privileged information. If you are notthe intended recipient, any disclosure, copying, use or distribution ofthe information included in the message and any attachments isprohibited. If you have received this communication in error, pleasenotify us by reply e-mail and immediately and permanently delete thismessage and any attachments. Thank You.
RE: [ActiveDir] Kix to .vbs
Have a look at http://www.lissware.net, vol 1, Sample 1.01 to 1.25 - WSHScript.vbs. This script contains all subroutines you need to read, write registry, env. variables, etc ... from .vbs. With this cscript, you will easily convert you kix script below into a .vbs. You just need to tweak the fucntion calls and return codes accordingly and reuse the set of registry keys your kix script references. HTH. Private Function GetRunTimeEnvInfo (classRunTimeEnvironmentInfo) Private Function LogRunTimeEnvInfo (objFileName, classRunTimeEnvironmentInfo) Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Private Function WriteRegistry (objFileName, strKeyName, KeyValueName, strRegType, varRegKeyValue) Private Function DeleteRegistry (objFileName, strKeyName, KeyValueName) Private Function EnumerateDriveConnections (objFileName) Private Function ConnectNetworkDrive (objFileName, strDriveLetter, strShareName) Private Function DisconnectNetworkDrive (objFileName, strDriveLetter, boolConfirm) Private Function EnumeratePrinterConnections (objFileName) Private Function ConnectWindowsNetworkPrinter (objFileName, strShareName, boolDefault) Private Function ConnectNetworkPrinter (objFileName, strLPT, strShareName) Private Function DisconnectNetworkPrinter (objFileName, strLPT, boolConfirm) Private Function ReadEnvironmentVariable (objFileName, strEnvironmentType, strVarName) Private Function CreateEnvironmentVariable (objFileName, strEnvironmentType, strVarName, varValue) Private Function RemoveEnvironmentVariable (objFileName, strEnvironmentType, strVarName) Private Function GetAllEnvironmentVariables (objFileName, strEnvironmentType) Private Function ReadCommandLineArgument (objFileName, strParameterList) Private Function ErrorHandler (objFileName, strFunctionName, Err, boolPopupErrors) Private Function CreateTextFile (strFileName) Private Function CloseTextFile (objFileName) Private Function WriteToFile (objFileName, strText) /Alain From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harding, DevonSent: Monday, November 14, 2005 8:49 AMTo: ActiveDir@mail.activedir.orgSubject: [ActiveDir] Kix to .vbs What would be the simplest way to convert this kix scrip to ..vbs? ; If workstation, exit script If @ProductType = "Windows 2000 Professional" or @ProductType = "Windows XP Professional" or @ProductType = "Windows NT Workstation" cls Exit Endif ; Check / Set VNC application hooks for logon.scr screen saver $ReturnCode = KeyExist("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr") If $ReturnCode=0 Addkey("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_Deferral",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_use_GetUpdateRect",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_KeyPress",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_LButtonUp",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_MButtonUp",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_RButtonUp",1,"reg_dword") WriteValue("HKCU\Software\ORL\VNCHooks\Application_Prefs\logon.scr","use_Timer",0,"reg_dword") EndIf ; Check / Set registry settings for BGINFO $ReturnCode = KeyExist("HKCU\Software\Winternals") If $ReturnCode = 0 Addkey("HKCU\Software\Winternals") EndIf $ReturnCode = KeyExist("HKCU\Software\Winternals\BGInfo") If $ReturnCode = 0 Addkey("HKCU\Software\Winternals\BGInfo") WriteValue("HKCU\Software\Winternals\BGInfo","Background",0,"reg_dword") WriteValue("HKCU\Software\Winternals\BGInfo","Foreground",16777215,"reg_dword") EndIf ; Run BGINFO from NetLogon share Run @Ldrive + "\bginfo.exe /i\\gsfps\netlogon\newbginfo.bgi /timer:0" ; Check / Set registry settings for screen saver. Logoff user if settings are updated $IsLocked = ReadValue("HKCU\Control Panel\Desktop","ScreenSaverIsSecure") $SSTimeOut = ReadValue("HKCU\Control Panel\Desktop","ScreenSaveTimeout") $SSActive = ReadValue("HKCU\Control Panel\Desktop","ScreenSaveActive") $ScrnSave = ReadValue("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If $IsLocked = 0 or (VAL($SSTimeOut) 900) or $SSActive = 0 or $ScrnSave = "" WriteValue("HKCU\Control Panel\Desktop","ScreenSaverIsSecure&q
Re: [ActiveDir] Kix to VBS
I have _vbscript_s using WSH extensively for handling computer migrations . I have used WMI just for finding the serialnumber of machine, everything else is handled by WSH. And my scripts are in the range of 500 to 10 K lines, and I have done some 3000+ migrations with these scripts. So, I can say WSH is no problem if you know what you want to do. besides that, WSH will be consistent across OS version. (at least NT and above, I have tested) while WMI has different number of classes available on different OS version. (more recent OS will have more classes) so if you find a class you want to use, you have to make sure that it is supported by all the OS version you going to run the script on. Generally, If i can do a task by WSH easily, i will not use WMI. ( you will tend to know the difference as you use them more and more) Good start for you would be the Microsoft Technet Script Center. http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx -- Kamlesh On 10/18/05, Alain Lissoir [EMAIL PROTECTED] wrote: If you are Windows and above and don't need REG_MULTI_SZ updates, I would gofor WSH (pretty simple model).If you need to do more complex stuffs, I would use WMI (which is actuallyused from WSH as it is the scripting engine). /Alain-Original Message-From: [EMAIL PROTECTED][mailto:[EMAIL PROTECTED] ] On Behalf Of Harding, DevonSent: Monday, October 17, 2005 9:45 AMTo: ActiveDir@mail.activedir.orgSubject: RE: [ActiveDir] Kix to VBSWhich method is preferred, WSH or WMI?
RE: [ActiveDir] Kix to VBS
Could I add multiple reg key changes to this vbs? I would have to define a new sPath at the end right? -Devon -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Almeida Pinto, Jorge de Sent: Friday, October 14, 2005 5:51 PM To: ActiveDir@mail.activedir.org; ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Hi, Try the following: Cheers, jorge 'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk /wmi/enumvalues_method_in_class_stdregprov.asp ### Const HKCU = H8001 Set oReg=GetObject(winmgmts:{impersonationLevel=impersonate}!\\.\root\defau lt:StdRegProv) sPath = Software\IXOS On Error Resume Next sKeyExist = False oReg.EnumKey HKCU, sPath, arrSubKeys For Each sSubKey In arrSubKeys If UCase(sSubKey) = IXOS_ARCHIVE Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = True Then sPath = Software\IXOS\IXOS_ARCHIVE\Viewer\Printing On Error Resume Next oReg.EnumKey HKCU, sPath, arrSubKeys sKeyExist = False For Each sSubKey In arrSubKeys If UCase(sSubKey) = FAX Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = False Then oReg.CreateKey HKCU, sPath \FAX oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 Else On Error Resume Next oReg.EnumValue HKCU, sPath, arrValueNames, arrValueTypes sValueExist = False For Each sValue In arrValueNames If sValue = PaperSize Then sValueExist = True Exit For End If Next Set sValue = Nothing Set arrValueNames = Nothing Set arrValueTypes = Nothing If sValueExist = True Then oReg.GetDWORDValue HKCU, sPath \FAX, PaperSize, MYValueData If MYValueData 1 Then oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If Else oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If End If End If ### From: [EMAIL PROTECTED] on behalf of Harding, Devon Sent: Fri 10/14/2005 7:48 PM To: ActiveDir@mail.activedir.org Subject: [ActiveDir] Kix to VBS I'm having a tough time converting this kix script to ..vbs. Any Ideas? ; This change will fix an IXOS problem where the default paper size is A4 instead of Letter If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE) = 1 If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) = 0 AddKey(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) EndIf If ReadValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSi ze) 1 WriteValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperS ize,1,reg_dword) EndIf EndIf Devon Harding Windows Systems Engineer Southern Wine Spirits - BSG 954-602-2469 __ This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use or distribution of the information included in the message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank You. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/ List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
RE: [ActiveDir] Kix to VBS
Subject: RE: [ActiveDir] Kix to VBS Could I add multiple reg key changes to this vbs? I would have to define a new sPath at the end right? -Devon -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Almeida Pinto, Jorge de Sent: Friday, October 14, 2005 5:51 PM To: ActiveDir@mail.activedir.org; ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Hi, Try the following: Cheers, jorge 'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk /wmi/enumvalues_method_in_class_stdregprov.asp ### Const HKCU = H8001 Set oReg=GetObject(winmgmts:{impersonationLevel=impersonate}!\\.\root\defau lt:StdRegProv) sPath = Software\IXOS On Error Resume Next sKeyExist = False oReg.EnumKey HKCU, sPath, arrSubKeys For Each sSubKey In arrSubKeys If UCase(sSubKey) = IXOS_ARCHIVE Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = True Then sPath = Software\IXOS\IXOS_ARCHIVE\Viewer\Printing On Error Resume Next oReg.EnumKey HKCU, sPath, arrSubKeys sKeyExist = False For Each sSubKey In arrSubKeys If UCase(sSubKey) = FAX Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = False Then oReg.CreateKey HKCU, sPath \FAX oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 Else On Error Resume Next oReg.EnumValue HKCU, sPath, arrValueNames, arrValueTypes sValueExist = False For Each sValue In arrValueNames If sValue = PaperSize Then sValueExist = True Exit For End If Next Set sValue = Nothing Set arrValueNames = Nothing Set arrValueTypes = Nothing If sValueExist = True Then oReg.GetDWORDValue HKCU, sPath \FAX, PaperSize, MYValueData If MYValueData 1 Then oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If Else oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If End If End If ### From: [EMAIL PROTECTED] on behalf of Harding, Devon Sent: Fri 10/14/2005 7:48 PM To: ActiveDir@mail.activedir.org Subject: [ActiveDir] Kix to VBS I'm having a tough time converting this kix script to ..vbs. Any Ideas? ; This change will fix an IXOS problem where the default paper size is A4 instead of Letter If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE) = 1 If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) = 0 AddKey(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) EndIf If ReadValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSi ze) 1 WriteValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperS ize,1,reg_dword) EndIf EndIf Devon Harding Windows Systems Engineer Southern Wine Spirits - BSG 954-602-2469 __ This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use or distribution of the information included in the message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank You. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/ List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/ List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/
RE: [ActiveDir] Kix to VBS
Which method is preferred, WSH or WMI? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 12:01 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Look at http://www.lissware.net, Volume 1, Sample 1.01 to 1.25 - WSHScript.vbs, which uses a series of functions. In this list of functions, you will find two generic routines to play with: ReadRegistryFunction.vbs and WriteRegistryFunction.vbs. With these two, you are all set. I reproed the ReadRegistry one below. Note that from the WSH object model, RegWrite method does not support REG_MULTI_SZ. If you need to update REG_MULTI_SZ, you need to use the WMI model. For this see http://www.lissware.net, Vol 2, Sample 3.03 to 3.09 - WMIRegistry.wsf (Second code exerpt below). HTH. ' Author: Alain Lissoir ([EMAIL PROTECTED]) ' ' ISBN 182664 - Understanding WMI Scripting (Digital Press) ' ISBN 182990 - Leveraging WMI Scripting (Digital Press) ' WSH Technique Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Dim strRegKey Dim varRegKeyValue() Dim intIndice Dim strTempValue On Error Resume Next strRegKey = strKeyName \ KeyValueName WriteToFile objFileName, ** Reading registry ' strRegKey '( strRegType ). strTempValue = WshShell.RegRead (strRegKey) If Err.Number Then ErrorHandler objFileName, ReadRegistry, Err, boolErrorPopup Exit Function End If Select Case strRegType Case REG_BINARY ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = h Right(00 Hex(strTempValue(intIndice)), 2) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_DWORD ReDim varRegKeyValue(0) varRegKeyValue(0) = h Hex (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case REG_MULTI_SZ ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = strTempValue(intIndice) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_EXPAND_SZ ReDim varRegKeyValue(0) varRegKeyValue(0) = WshShell.ExpandEnvironmentStrings (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case Else ReDim varRegKeyValue(0) varRegKeyValue(0) = strTempValue WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) End Select ReadRegistry = varRegKeyValue End Function ' WMI technique -- Select Case intKeyType Case REG_SZ intRC = objWMIClass.SetStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_MULTI_SZ intRC = objWMIClass.SetMultiStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_EXPAND_SZ intRC = objWMIClass.SetExpandedStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_BINARY intRC = objWMIClass.SetBinaryValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_DWORD intRC = objWMIClass.SetDWORDValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) End Select -Original Message- From: [EMAIL
RE: [ActiveDir] Kix to VBS
Devon, my personal opinion is to avoid WSH when possible, just because I have run into cases wehre I used a vbscript custom action in an MSI package, and the WSH is unavailable [1] to the Windows Installer. Since I ran that, if I think I might need to use this cool new thing I figured out how to do with vbscript in an MSI, then I try to use WMI or other methods, even if WSH exposes them more easily. But that's my personal preference, and I am by no means a scripting guru :) Rich [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/set up/scripts.asp: Note The installer runs script custom actions directly and does not use the Windows Script Host. The WScript object cannot be used inside a script custom action because this object is provided by the Windows Script Host. Objects in the Windows Script Host object model can only be used in custom actions if Windows Script Host is installed on the computer by creating new instances of the object, with a call to CreateObject, and providing the ProgId of the object (for example WScript.Shell). Depending on the type of script custom action, access to some objects and methods of the Windows Script Host object model may be denied for security reasons. --- Rich Milburn MCSE, Microsoft MVP - Directory Services Sr Network Analyst, Field Platform Development Applebee's International, Inc. 4551 W. 107th St Overland Park, KS 66207 913-967-2819 -- I am always doing that which I can not do, in order that I may learn how to do it. - Pablo Picasso -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harding, Devon Sent: Monday, October 17, 2005 11:45 AM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Which method is preferred, WSH or WMI? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 12:01 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Look at http://www.lissware.net, Volume 1, Sample 1.01 to 1.25 - WSHScript.vbs, which uses a series of functions. In this list of functions, you will find two generic routines to play with: ReadRegistryFunction.vbs and WriteRegistryFunction.vbs. With these two, you are all set. I reproed the ReadRegistry one below. Note that from the WSH object model, RegWrite method does not support REG_MULTI_SZ. If you need to update REG_MULTI_SZ, you need to use the WMI model. For this see http://www.lissware.net, Vol 2, Sample 3.03 to 3.09 - WMIRegistry.wsf (Second code exerpt below). HTH. ' Author: Alain Lissoir ([EMAIL PROTECTED]) ' ' ISBN 182664 - Understanding WMI Scripting (Digital Press) ' ISBN 182990 - Leveraging WMI Scripting (Digital Press) ' WSH Technique Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Dim strRegKey Dim varRegKeyValue() Dim intIndice Dim strTempValue On Error Resume Next strRegKey = strKeyName \ KeyValueName WriteToFile objFileName, ** Reading registry ' strRegKey '( strRegType ). strTempValue = WshShell.RegRead (strRegKey) If Err.Number Then ErrorHandler objFileName, ReadRegistry, Err, boolErrorPopup Exit Function End If Select Case strRegType Case REG_BINARY ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = h Right(00 Hex(strTempValue(intIndice)), 2) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_DWORD ReDim varRegKeyValue(0) varRegKeyValue(0) = h Hex (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case REG_MULTI_SZ ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = strTempValue(intIndice) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_EXPAND_SZ ReDim varRegKeyValue(0) varRegKeyValue(0) = WshShell.ExpandEnvironmentStrings (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0
RE: [ActiveDir] Kix to VBS
If you are Windows and above and don't need REG_MULTI_SZ updates, I would go for WSH (pretty simple model). If you need to do more complex stuffs, I would use WMI (which is actually used from WSH as it is the scripting engine). /Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harding, Devon Sent: Monday, October 17, 2005 9:45 AM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Which method is preferred, WSH or WMI? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 12:01 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Look at http://www.lissware.net, Volume 1, Sample 1.01 to 1.25 - WSHScript.vbs, which uses a series of functions. In this list of functions, you will find two generic routines to play with: ReadRegistryFunction.vbs and WriteRegistryFunction.vbs. With these two, you are all set. I reproed the ReadRegistry one below. Note that from the WSH object model, RegWrite method does not support REG_MULTI_SZ. If you need to update REG_MULTI_SZ, you need to use the WMI model. For this see http://www.lissware.net, Vol 2, Sample 3.03 to 3.09 - WMIRegistry.wsf (Second code exerpt below). HTH. ' Author: Alain Lissoir ([EMAIL PROTECTED]) ' ' ISBN 182664 - Understanding WMI Scripting (Digital Press) ' ISBN 182990 - Leveraging WMI Scripting (Digital Press) ' WSH Technique Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Dim strRegKey Dim varRegKeyValue() Dim intIndice Dim strTempValue On Error Resume Next strRegKey = strKeyName \ KeyValueName WriteToFile objFileName, ** Reading registry ' strRegKey '( strRegType ). strTempValue = WshShell.RegRead (strRegKey) If Err.Number Then ErrorHandler objFileName, ReadRegistry, Err, boolErrorPopup Exit Function End If Select Case strRegType Case REG_BINARY ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = h Right(00 Hex(strTempValue(intIndice)), 2) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_DWORD ReDim varRegKeyValue(0) varRegKeyValue(0) = h Hex (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case REG_MULTI_SZ ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = strTempValue(intIndice) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_EXPAND_SZ ReDim varRegKeyValue(0) varRegKeyValue(0) = WshShell.ExpandEnvironmentStrings (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case Else ReDim varRegKeyValue(0) varRegKeyValue(0) = strTempValue WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) End Select ReadRegistry = varRegKeyValue End Function ' WMI technique -- Select Case intKeyType Case REG_SZ intRC = objWMIClass.SetStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_MULTI_SZ intRC = objWMIClass.SetMultiStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_EXPAND_SZ intRC = objWMIClass.SetExpandedStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_BINARY intRC = objWMIClass.SetBinaryValue (intHiveType, _ strBaseKey, _ strKeyName
RE: [ActiveDir] Kix to VBS
I've always had better luck with WMI. YMMV -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harding, Devon Sent: Monday, October 17, 2005 10:45 AM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Which method is preferred, WSH or WMI? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 12:01 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Look at http://www.lissware.net, Volume 1, Sample 1.01 to 1.25 - WSHScript.vbs, which uses a series of functions. In this list of functions, you will find two generic routines to play with: ReadRegistryFunction.vbs and WriteRegistryFunction.vbs. With these two, you are all set. I reproed the ReadRegistry one below. Note that from the WSH object model, RegWrite method does not support REG_MULTI_SZ. If you need to update REG_MULTI_SZ, you need to use the WMI model. For this see http://www.lissware.net, Vol 2, Sample 3.03 to 3.09 - WMIRegistry.wsf (Second code exerpt below). HTH. ' Author: Alain Lissoir ([EMAIL PROTECTED]) ' ' ISBN 182664 - Understanding WMI Scripting (Digital Press) ' ISBN 182990 - Leveraging WMI Scripting (Digital Press) ' WSH Technique Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Dim strRegKey Dim varRegKeyValue() Dim intIndice Dim strTempValue On Error Resume Next strRegKey = strKeyName \ KeyValueName WriteToFile objFileName, ** Reading registry ' strRegKey '( strRegType ). strTempValue = WshShell.RegRead (strRegKey) If Err.Number Then ErrorHandler objFileName, ReadRegistry, Err, boolErrorPopup Exit Function End If Select Case strRegType Case REG_BINARY ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = h Right(00 Hex(strTempValue(intIndice)), 2) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_DWORD ReDim varRegKeyValue(0) varRegKeyValue(0) = h Hex (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case REG_MULTI_SZ ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = strTempValue(intIndice) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_EXPAND_SZ ReDim varRegKeyValue(0) varRegKeyValue(0) = WshShell.ExpandEnvironmentStrings (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case Else ReDim varRegKeyValue(0) varRegKeyValue(0) = strTempValue WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) End Select ReadRegistry = varRegKeyValue End Function ' WMI technique -- Select Case intKeyType Case REG_SZ intRC = objWMIClass.SetStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_MULTI_SZ intRC = objWMIClass.SetMultiStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_EXPAND_SZ intRC = objWMIClass.SetExpandedStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_BINARY intRC = objWMIClass.SetBinaryValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_DWORD intRC = objWMIClass.SetDWORDValue (intHiveType
RE: [ActiveDir] Kix to VBS
I meant if you are Windows 2000 and above ... -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 5:12 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS If you are Windows and above and don't need REG_MULTI_SZ updates, I would go for WSH (pretty simple model). If you need to do more complex stuffs, I would use WMI (which is actually used from WSH as it is the scripting engine). /Alain -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Harding, Devon Sent: Monday, October 17, 2005 9:45 AM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Which method is preferred, WSH or WMI? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alain Lissoir Sent: Monday, October 17, 2005 12:01 PM To: ActiveDir@mail.activedir.org Subject: RE: [ActiveDir] Kix to VBS Look at http://www.lissware.net, Volume 1, Sample 1.01 to 1.25 - WSHScript.vbs, which uses a series of functions. In this list of functions, you will find two generic routines to play with: ReadRegistryFunction.vbs and WriteRegistryFunction.vbs. With these two, you are all set. I reproed the ReadRegistry one below. Note that from the WSH object model, RegWrite method does not support REG_MULTI_SZ. If you need to update REG_MULTI_SZ, you need to use the WMI model. For this see http://www.lissware.net, Vol 2, Sample 3.03 to 3.09 - WMIRegistry.wsf (Second code exerpt below). HTH. ' Author: Alain Lissoir ([EMAIL PROTECTED]) ' ' ISBN 182664 - Understanding WMI Scripting (Digital Press) ' ISBN 182990 - Leveraging WMI Scripting (Digital Press) ' WSH Technique Private Function ReadRegistry (objFileName, strKeyName, KeyValueName, strRegType) Dim strRegKey Dim varRegKeyValue() Dim intIndice Dim strTempValue On Error Resume Next strRegKey = strKeyName \ KeyValueName WriteToFile objFileName, ** Reading registry ' strRegKey '( strRegType ). strTempValue = WshShell.RegRead (strRegKey) If Err.Number Then ErrorHandler objFileName, ReadRegistry, Err, boolErrorPopup Exit Function End If Select Case strRegType Case REG_BINARY ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = h Right(00 Hex(strTempValue(intIndice)), 2) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_DWORD ReDim varRegKeyValue(0) varRegKeyValue(0) = h Hex (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case REG_MULTI_SZ ReDim varRegKeyValue(Ubound(strTempValue)) For intIndice = 0 to Ubound(strTempValue) varRegKeyValue (intIndice) = strTempValue(intIndice) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(intIndice) Next Case REG_EXPAND_SZ ReDim varRegKeyValue(0) varRegKeyValue(0) = WshShell.ExpandEnvironmentStrings (strTempValue) WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) Case Else ReDim varRegKeyValue(0) varRegKeyValue(0) = strTempValue WriteToFile objFileName, _ strRegKey ( UCase(strRegType) ) - varRegKeyValue(0) End Select ReadRegistry = varRegKeyValue End Function ' WMI technique -- Select Case intKeyType Case REG_SZ intRC = objWMIClass.SetStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_MULTI_SZ intRC = objWMIClass.SetMultiStringValue (intHiveType, _ strBaseKey, _ strKeyName, _ varKeyNameValue) Case REG_EXPAND_SZ intRC = objWMIClass.SetExpandedStringValue (intHiveType, _ strBaseKey, _ strKeyName
Re: [ActiveDir] Kix to VBS
use regread for keyexist and readvalue functions of shell object regwrite for addkey writevalue fucntions while, _vbscript_ will exit with error if regread couldn't find the key, you can use on error resume next before validating the key existence, to continue the script execution. reference: http://msdn.microsoft.com/library/default.asp?url=""> On 10/14/05, Harding, Devon [EMAIL PROTECTED] wrote: I'm having a tough time converting this kix script to ..vbs. Any Ideas? ; This change will fix an IXOS problem where the default paper size is A4 instead of Letter If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE) = 1 If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) = 0 AddKey(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) EndIf If ReadValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSize) 1 WriteValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSize,1,reg_dword) EndIf EndIf Devon Harding Windows Systems Engineer Southern Wine Spirits - BSG 954-602-2469 __This message and any attachments are solely for the intended recipientand may contain confidential or privileged information. If you are notthe intended recipient, any disclosure, copying, use or distribution of the information included in the message and any attachments isprohibited. If you have received this communication in error, pleasenotify us by reply e-mail and immediately and permanently delete thismessage and any attachments. Thank You. -- ~~~Fortune and Love befriend the bold~~~
RE: [ActiveDir] Kix to VBS
Hi, Try the following: Cheers, jorge 'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/enumvalues_method_in_class_stdregprov.asp ### Const HKCU = H8001 Set oReg=GetObject(winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv) sPath = Software\IXOS On Error Resume Next sKeyExist = False oReg.EnumKey HKCU, sPath, arrSubKeys For Each sSubKey In arrSubKeys If UCase(sSubKey) = IXOS_ARCHIVE Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = True Then sPath = Software\IXOS\IXOS_ARCHIVE\Viewer\Printing On Error Resume Next oReg.EnumKey HKCU, sPath, arrSubKeys sKeyExist = False For Each sSubKey In arrSubKeys If UCase(sSubKey) = FAX Then sKeyExist = True Exit For End If Next Set sSubKey = Nothing Set arrSubKeys = Nothing If sKeyExist = False Then oReg.CreateKey HKCU, sPath \FAX oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 Else On Error Resume Next oReg.EnumValue HKCU, sPath, arrValueNames, arrValueTypes sValueExist = False For Each sValue In arrValueNames If sValue = PaperSize Then sValueExist = True Exit For End If Next Set sValue = Nothing Set arrValueNames = Nothing Set arrValueTypes = Nothing If sValueExist = True Then oReg.GetDWORDValue HKCU, sPath \FAX, PaperSize, MYValueData If MYValueData 1 Then oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If Else oReg.SetDWORDValue HKCU, sPath \FAX, PaperSize, 1 End If End If End If ### From: [EMAIL PROTECTED] on behalf of Harding, Devon Sent: Fri 10/14/2005 7:48 PM To: ActiveDir@mail.activedir.org Subject: [ActiveDir] Kix to VBS I'm having a tough time converting this kix script to ..vbs. Any Ideas? ; This change will fix an IXOS problem where the default paper size is A4 instead of Letter If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE) = 1 If KeyExist(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) = 0 AddKey(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX) EndIf If ReadValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSize) 1 WriteValue(HKCU\Software\IXOS\IXOS_ARCHIVE\Viewer\Printing\FAX,PaperSize,1,reg_dword) EndIf EndIf Devon Harding Windows Systems Engineer Southern Wine Spirits - BSG 954-602-2469 __ This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use or distribution of the information included in the message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank You. This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. List info : http://www.activedir.org/List.aspx List FAQ: http://www.activedir.org/ListFAQ.aspx List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/