Change Wallpaper in Windows 7 - 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

Related

VBScript to open, run and close Tor browser

Please edit this VBScript to open, run and close Tor browser:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Exec("""C:\Users\Name\Desktop\Tor\Tor Browser\Browser\Tor.exe""/http://www.google.com")
Set objShell = Nothing
WScript.Sleep 20000
Set objShell = objshell.Exec("taskkill /fi ""imagename eq Tor.exe""")
It opens and runs, but doesn't close.
You should try something like this :
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "Taskkill /F /IM Tor.exe",0,True

Add file to HKEY_CURRENT_USER Autorun AND HKEY_LOCAL_MACHINE in only ONE script

I have this VBScript:
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
WshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"
Set WshShell = Nothing
which adds
"C:\Program Files (x86)\example.exe"
to the startup registry
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
Now I also want to add
"C:\Program Files (x86)\example.exe"
to the startup registry
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\example"
How can you do that in only ONE SINGLE VBScript?
I tried to just modify this code:
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\example"
WshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"
Set WshShell = Nothing
so that it would add the program to HKEY_LOCAL_MACHINE and then paste it underneath, but that didn't work.
Dim wshShell
Dim myKey
Set wshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run\example"
wshShell.RegWrite myKey, "C:\Program Files (x86)\example.exe", "REG_SZ"

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

Computername write to txt file (%computername%)

If a computer run's the script on Wednesday, i want that it creates a %computername*.txt file in a netwok map. In batch script i can to it with %computername%.txt, what code can i use it for VBS script?
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
If DatePart("W",Date) = 4 Then
'Today is Wednesday, so run the virus scan
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\%COMPUTERNAME%.txt")
WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If
>> WScript.Echo CreateObject("WScript.Shell").ExpandEnvironmentStrings("%COMPUTERNAME%")
>>
WINXPSP3
>> WScript.Echo CreateObject("WScript.Network").Computername
>>
WINXPSP3
Use the WshNetwork object to get the computer name as suggested. It looks like this.
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = CreateObject("WScript.Network")
strComputer = WshNetwork.ComputerName
If DatePart("W",Date) = 4 Then
'Today is Wednesday, so run the virus scan
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\server\Avast Scan Log\" & strComputer & ".txt")
WshShell.Run """C:\Program Files\Alwil Software\Avast4\aswcmd"" M: /m /*", , True
End If

Resources