Update registry key if equal to a value with VBS - vbscript

i would like to update a registry key value if equal to "1" then Change it to "2"
If =2 then no action
with VBS
Example :
HKEY_CURRENT_USER\Software
VALUE1 = 1
Please help

Set WshShell = WScript.CreateObject("WScript.Shell")
' read the valor
Val01=WshShell.RegRead ("HKEY_CURRENT_USER\Software\Value1")
' if valor = 1 then change 1 > 2
msgbox Val01
if val01=1 then
WshShell.RegWrite "HKEY_CURRENT_USER\Software\Value1",2, "REG_SZ"
end if

Related

vbscript wont do "if" properly [duplicate]

This question already has answers here:
How can I show a message box with two buttons?
(8 answers)
Closed 1 year ago.
I was creating a vbs but after i click Yes in msgbox, it instead does what the "No" is supposed to do.
Here is my code:
X=MsgBox("Please Restart. Our system will break down.",4+4096, ErR0r)
if vbNo then
X=MsgBox("e")
dim count
set object = wscript.CreateObject("wscript.shell")
do
object.run "error.vbs"
count = count + 1
loop until count = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
end if
if vbYes then
Dim IntCounter
Dim objWshShl : Set objWshShl = WScript.CreateObject("wscript.shell")
Dim objVoice : Set objVoice = WScript.CreateObject("sapi.spvoice")
ShutdownWarning()
TimedMessageBox()
ShutdownComputer()
Function ShutdownWarning
X=MsgBox("happy late april fools, hehe", 0+4096)
WScript.Sleep 5000
End Function
Function TimedMessageBox
For IntCounter = 5 To 1 Step -1
objWshShl.Popup "Your time will be wasted in " _
& IntCounter & " seconds",1,"Computer Shutdown", 0+4096
Next
End Function
Function ShutdownComputer
objWshShl.Run "Shutdown /s /f /t 0",0
End Function
end if
does anyone have solutions to this?
(im not trying to create a legitimate virus, this is just a prank i made for fun)
vbNo is a constant value equal to 7.
if vbNo will always be true, since 7 is not a falsy value.
You need to use a variable to get the return value of the user input, such as :
userInput = msgBox("click yes or no", vbYesNo)
if userInput = vbNo Then
' do something
end if

Vbscript to run .Bat file with parameters and search for error in result txt file

I am preparing vbscript to run bat files where bat file name contains version number, Script have to search for bat file with matching version name . Once Ran,The result Text file will be generated with same version number. I have to search for Text file with same version number and read the txt file for error or msg, if error found i want to display it.
I know my requirement is little too much.
But I am finding little difficulty in debugging the code.I am stuck.
Can any one help me to resolve the issue.
Thank You
here is my script,
I am passing values for sql query from excel sheet.
Dim Ver, Version_Number
Dim con
Dim rs
Set con=createobject("adodb.connection")
Set rs=Createobject("adodb.recordset")
Set PinXL = CreateObject("Excel.application")
Set PinWB = PinXL.Workbooks.Open("C:\maspects\Trial.xls") '// Login and Enable Debug Window in application
Set PinWS = PinWB.Worksheets("Sheet1")
varr = Cstr(PinWS.Cells(2,1).Value)
varr1 = trim(varr)
usename = Cstr(PinWS.Cells(2,2).Value)
UN = trim(usename)
password = Cstr(PinWS.Cells(2,3).Value)
PWD = trim(password)
IrisDB = Cstr(PinWS.Cells(2,4).Value)
DB = trim(IrisDB)
Site_Name = Cstr(PinWS.Cells(2,5).Value)
Site = trim(Site_Name)
con.open"provider=sqloledb.1;server=" & varr1 & ";uid=" & UN & ";pwd=" & PWD & ";database=" & DB &""
Wscript.sleep 1000*3
rs.Open "select * from tblSettingsUnique where [Setting Name] like '%Revision%'" ,con
Wscript.sleep 1000*2
Version_Number = rs.Fields("Setting Value")
Ver = Version_Number
msgbox Ver
Call Execute
PinWB.Save
PinWB.Close
PinXL.Quit
Wscript.Quit
Function Execute
If Ver < PinWS.Cells(2,6).Value = "True" Then ' if Ver is less than Cell(2,6) value then application should come out of loop
For i = Ver to PinWS.Cells(2,6).Value step 1
msgbox i
Set WShell = CreateObject("WScript.Shell")
For each f in Wshell.Getfolder("C:\maspects\DB_script").Files
BatFile = instr(f.File , "4_0_"&i )
WShell.Run ("CMD /K C:\maspects\DB_script\"&batFile &".bat" & Varr1 &" "& UN &" "& password )
Call msg
Next
Next
End If
End Function
Function msg
Set TxtObject = CreateObject("scripting.FileSystemObject")
For each ResFile in TxtObject.GetFolder("C:\maspects\DB_script").Files
TargetFile = InStr(ResFile.File , "4_0_"&i )
Set TxtFile = TxtObject.openTextFile("C:\maspects\DB_script\"&TargetFile, 1 ,true)
Do until TxtFile.AtEndOfStream
For each F in TxtFile.Readline
if InStr (F,"msg" ) = "True" and InStr (F,"msg 207" )= "False" Then
msgbox "Error in:"&TargetFile
React =Cint(Inputbox("Go through the Result file:"&TargetFile &"Enter '1' to Continue '0' to Quit"))
If React = "0" Then
TextObject.Close
Wscript.Quit
End if
End If
Next
Loop
TextObject.Close
Next
End Function

can someone check my coding here pls

This VBScript should get a random number between 1 and 3, and then type the letter according to the number and type it into the notepad that it opened and then goto the next line, but for some reason it doesn't enter the letter. Can someone explain the problem to me please? Here is the code:
Set ws = CreateObject("WScript.Shell")
ws.Run "notepad.exe"
Wscript.Sleep 100
do
RAND = Int((3 - 1 + 1) * Rnd + 1)
if RAND=1 Then
key = a
elseif RAND=2 Then
key = b
elseif RAND=3 Then
key = c
end if
ws.SendKeys key
ws.SendKeys "{ENTER}"
Wscript.sleep 1000
loop
key="a"
Place Option Explicit as the first line of the file and you will see that you are trying to assign non defined variables instead of string literals
Did you define a, b, c?
Maybe you mean:
if RAND=1 Then
key = "a"
elseif RAND=2 Then
key = "b"
elseif RAND=3 Then
key = "c"
end if

VBS Object required error, 800A01A8

Hello I'm trying to debug this script that I inherited below. The error is on line 71 char 6. Object required 'oFile'
I don't have any vbs experience so please be gentle. This script takes a scan and uploads it to a doc archive server, gives it unique filename etc. I haven't figured out what 'ofile' is yet :/
'Feb 18, 2005
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
hiddenCount = 0
'Wscript.Echo Wscript.Arguments(0)
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then
Set scanFiles = oFSO.GetFolder(Wscript.Arguments(0)).Files
For Each oFile In scanFiles
If oFile.Attributes and 2 Then
hiddenCount = hiddenCount + 1
End If
Next
Else
Set scanFiles = WScript.Arguments
End If
fileCount = scanFiles.Count - hiddenCount
'Wscript.Echo hiddenCount
'WScript.Echo fileCount
'WScript.Quit()
Set oIE = WScript.CreateObject("InternetExplorer.Application")
oIE.left=50 ' window position
oIE.top = 100 ' and other properties
oIE.height = 300
oIE.width = 350
oIE.menubar = 0 ' no menu
oIE.toolbar = 0
oIE.statusbar = 1
oIE.navigate "http://gisweb/apps/doc_archive/scan_login.php?file_count="&fileCount
'WScript.Echo fileCount
oIE.visible = 1
' Important: wait till MSIE is ready
Do While (oIE.Busy)
Loop
' Wait till the user clicks the OK button
' Use the CheckVal function
' Attention: Thanks to a note from M. Harris, we can make
' the script a bit more fool proof. We need to catch the case
' that the user closes the form without clicking the OK button.
On Error Resume Next
Do ' Wait till OK button is clicked
WScript.Sleep 400
Loop While (oIE.document.script.CheckVal()=0)
' If an error occur, because the form is closed, quit the
' script
If err <> 0 Then
WScript.Echo "Sorry, a run-time error occured during checking" & _
" the OK button " & vbCRLF & _
"Error: " & err.number & " " & _
"I guess the form was getting closed..."
WScript.Quit ' end script
End if
On Error Goto 0 ' switch error handling off
' User has clicked the OK button, retrieve the values
docList = oIE.Document.ValidForm.doc_id_list.Value
'MsgBox doc_id
For i = 0 To 100000
x = 1
Next
oIE.Quit() ' close Internet Explorer
Set oIE = Nothing ' reset object variable
docArray = Split(docList,",")
i = 0
For Each oFile In scanFiles
If Not oFile.Attributes And 2 Then **ERROR HERE**
ext = oFSO.GetExtensionName(oFile)
filename = "p"&right("000000"&docArray(i),6)&"."&ext
base = Int(docArray(i) / 500) * 500
subdir = "d"&right("000000"&base,6)
oFSO.CopyFile oFile, "\\ditgis02\Enterprise_GIS\doc_archive\raw\"&subdir&"\"&filename, True
i = i + 1
End If
Next
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then
Set WshShell = WScript.CreateObject("WScript.Shell")
intButton = WshShell.Popup (fileCount&" file(s) logged and copied! Do you want to delete temporary scan files?",0,"Done!",4)
If intButton = 6 Then
For Each oFile In scanFiles
oFile.Delete
Next
End If
Else
WScript.Echo(fileCount&" file(s) logged and copied!")
End If
WScript.Quit() ' Ready
' End
It looks the problem may arise if your initial test fails:
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then
...
Else
Set scanFiles = WScript.Arguments
End If
You're setting the scanFiles variable to a collection of arguments, not files. Later on, near line 71 (where your error occurs), you're treating scanFiles as if it's a Files collection and attempting to access the Attributes property of one of its File objects:
For Each oFile In scanFiles
If Not oFile.Attributes And 2 Then **ERROR HERE**
...
Next
This won't be possible since scanFiles is an Arguments collection instead. So I think you need to fix your initial Else clause to either terminate your script or provide some kind of "default" Files collection.

VBS script error

Im getting this error when i try to run my vbs script,
object doesnt support this property or method
My vbs code is
Rem -- This example will show you how to create a very simple runonce configuration.
Rem -- Get current path of this script.
Set fso = CreateObject("Scripting.FileSystemObject")
currentdir = fso.GetAbsolutePathName(".")
Rem -- Read the info xml
Set xmldom = CreateObject("MSXML.DOMDocument")
xmldom.Load("c:\Montupet\PDF" & "\info.xml")
Rem -- Get the program id of the automation object.
progid = xmldom.SelectSingleNode("/xml/progid").text
Rem -- Create the COM object to control the printer.
set obj = CreateObject(progid)
Rem -- Get the default printer name.
Rem -- You can override this setting to specify a specific printer.
printername = "PDF Writer - bioPDF"
runonce = obj.GetSettingsFileName(true)
^
Error here
set oArgs=wscript.Arguments
Rem -- Print all the files in the 'in' folder
dim file_name, template
dim command_line_args
set command_line_args = wscript.Arguments
'Check if any Arguments have been passed to our script.
if command_line_args.count > 0 then
file_name = command_line_args(0)
template = command_line_args(1)
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
wordname = """" & "c:\MTMS\MTMSPRT\" & file_name & """"
wscript.echo wordname
Set oDoc = oWd.Documents.Open(wordname)
Set oPS = oDoc.PageSetup
' Reduce the margins to .5" (36 points)
oPS.LeftMargin = 8.4
oPS.RightMargin = 0.2
'Save changes to doc on closing and quit Word
oDoc.Saveas wordname , 0
wscript.echo "Saved"
oDoc.Close
wscript.echo "close"
oWd.Quit
wscript.echo "Quit"
Set oWd = Nothing
Set objShell = Nothing
wscript.echo "Cleared Word"
Set oWd = Nothing
Set objShell = Nothing
output = "c:\MTMS\MTMSPRT\PDFs\" & Replace(ucase(file_name), "DOC", "") & "PDF"
Rem -- Set the values
obj.Init
obj.SetValue "Output", output
obj.SetValue "ShowSettings", "never"
obj.SetValue "ShowPDF", "no"
obj.SetValue "ShowProgress", "no"
obj.SetValue "ShowProgressFinished", "no"
obj.SetValue "SuppressErrors", "no"
obj.SetValue "ConfirmOverwrite", "no"
obj.SetValue "superimpose", template
Rem -- Write settings to the runonce-Invoice.ini
obj.WriteSettings True
wscript.echo "runonce created"
Rem -- Print the document
printfile = "c:\MTMS\MTMSPRT\" & file_name
cmd = """" & "c:\Montupet\PDF\printto.exe"" """ & printfile & """ """ & printername & """"
wscript.echo "printfile line setup"
Set WshShell = WScript.CreateObject("WScript.Shell")
ret = WshShell.Run(cmd, 1, true)
wscript.echo "shell run start"
Rem -- Wait until the runonce is removed.
Rem -- When the runonce is removed it means that the gui.exe program
rem -- has picked up the print job and is ready for the next.
While fso.fileexists(runonce)
wscript.echo "checking for runonce"
Rem -- Wait for some milliseconds before testing again
wscript.sleep 100
Wend
wscript.echo "runonce gone"
end if
Rem -- Dispose the printer control object
set obj = Nothing
Judging by this blog post for VB6,
runonce = obj.GetSettingsFileName(true)
should instead be
runonce = obj.GetSettingsFilePath(true)
The BioPDF website has a reference which might help further.

Resources