objshell.regwrite wont work - vbscript

It works with:
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoFolderOptions", 1, "REG_DWORD"
Set objShell = Nothing
But it doesn't work with:
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDrives", 3FFFFFF, "REG_DWORD"
Set objShell = Nothing
For the second one it will have an end of statement error. Why is that?

Your answer is here (read the whole page, there is also vbs example code).
Note that only decimal values can be added as strings (as described in the article).

You get the error because 3FFFFF is neither a valid variable name nor valid notation for a hexadecimal number. Try this:
objShell.RegWrite "HKCU\...\NoDrives", &h3FFFFFF, "REG_DWORD"

Related

VBS Windows proxy enable

Option Explicit
Dim objShell, RegLocate
Set objShell = WScript.CreateObject("WScript.Shell")
RegLocate = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"
objShell.RegWrite RegLocate,"0","REG_DWORD"
WScript.Sleep 1000
If "REG_DWORD" = "" then
CreateObject("WScript.Shell").RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet\Settings\ProxyEnable Settings\ProxyEnable",1,"REG_DWORD"
else
MsgBox "Proxy alrdy running"
end if
WScript.Quit
So my problem is not to get the proxy settings in, I have script for that and it works. The problem is to enable it in IE explorer.
The script runs and don't get an error... so I have hit a wall.
Sorry for bad grammar and English.

Why does this small vbscript to change desktop background work intermittently, not all the time?

A small VBscript in order to change the desktop background automatically, practically for demo purposes:
dim wshShell
dim sUserName
Set wshShell = WScript.CreateObject("WScript.Shell")
Set oShell = CreateObject("WScript.Shell")
currWallPaper = oShell.RegRead("HKCU\Software\Microsoft\InternetExplorer\Desktop\General\Wallpap erSource")
If currWallPaper = "C:\Users\Utsav\Pictures\493889.png" Then
msgbox "OK1"
sWallPaper = "C:\Users\Utsav\Pictures\336180.png"
ElseIf currWallPaper = "C:\Users\Utsav\Pictures\336180.png" Then
sWallPaper = "C:\Users\Utsav\Pictures\1920-1080-278658.png"
Else
sWallPaper = "C:\Users\Utsav\Pictures\493889.png"
End If
' update in registry
oShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", sWallPaper
' let the system know about the change
oShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters", 1, True
msgbox "done"
This script works only intermittently, i.e. on executing from command line it will change the background only once in about 4-5 attempts. Any ideas explaining the reason for this behaviour would be most welcome.

VBScript to enable / disable proxy

I'm trying to create a script to go into startup applications which will automatically set the proxy in my workplace. The idea is this however I'm new to VBScript and I keep getting an error.
Option Explicit
Dim WSHShell, strSetting
ans = msgbox("Are you working in the office?" , vbyesno)
If ans = vbyes then
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 1, "REG_DWORD"
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", "10.2.2.88:8090", "REG_SZ"
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride", "*.dev;*.test;*.local;<local>", "REG_SZ"
else
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable", 0, "REG_DWORD"
End If
Can somebody show me where I'm going wrong?
Thanks!
Suppose your error is something as follows:
==>cscript //nologo D:\VB_scripts\SO\28832310.vbs
28832310.vbs(3, 1) Microsoft VBScript runtime error: Variable is undefined: 'ans'
Self-explanatory message, IMHO. As you have used Option Explicit statement correctly (forces explicit declaration of all variables in a script), simply add ans variable declaration, i.e. use
Dim WSHShell, strSetting, ans

VBS Case Statement is failing

This case statement is failing...it is like it never even sees it any help would be greatly appreciated.
Dim Runmode
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("D:\Program Files (x86)\Logility\SPC8.0\Input\FG352F.txt",1)
RunMode = objFileToRead.ReadAll()
objFileToRead.Close
Set objFileToRead = Nothing
MsgBox(RunMode)
select Case RunMode
Case "D"
Set oShell = CreateObject("WSCript.shell")
oShell.run "D:\Scripts\RTL_DAILY.bat"
Case "W"
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "D:\Scripts\RTL_WEEKLY.bat"
Case "M"
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "D:\Scripts\RTL_MONTHLY.bat"
End Select
Assuming the file contains a single letter like "M" and perhaps an EOL, use .ReadLine() to get rid of the EOL automagically.
In general, a Case Else to catch (and dump) surprises is always a good idea.

Change Wallpaper in Windows 7

I have written a small vbs script to download and change the registry for the current users wallpaper. however it copies and does the change but the wallpaper does not change... any ideas on errors in the below code?
Option Explicit
Dim WshShell, strValue, sleepTime, oFSO
strValue = "C:\wallpaper.bmp"
sleepTime = 30000
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFile "\\anspksnms1\OSD\Scripts\wallpaper\wallpaper.bmp", "C:\"
Set WshShell = WScript.CreateObject("Wscript.Shell")
WshShell.RegWrite "HKCU\Control Panel\Desktop\Wallpaper", strValue
WScript.Sleep sleepTime
WshShell.Run "%windir%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters", 1, False
Set WshShell = Nothing
I'm not much of a vbscripter, but maybe try this?
wshShell.run "cmd /c RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters", 1, True

Resources