What is the proper syntax for ".Stop" method for "Schedule.Service"? - vbscript

I have some tasks that need to be removed. Some users have installed Chrome under their own profile and the only way to remove it is to "nuke" it since it is not feasible to log in with their account and do the uninstall the proper way. The scheduled tasks have a user sid added to the end of the name, so I have to search for a task with "GoogleUpdate" in the string. When I remove a service, I like to stop the service, disable the service, then delete it. I want to do the same thing with the scheduled tasks. After a lot of scouring of the web, I have found the syntax to disable, delete and that works perfect, but not how to stop. I would prefer not to shell out and use schtasks since I have come this far with a 200 + line script using all VbScript.
Here is what I have so far. I need help figuring out the syntax for the ".Stop" method. If anyone has an example of the stop method, it would be much appreciated.
Set objTaskService = CreateObject("Schedule.Service")
Call objTaskService.Connect()
Set objTaskFolder = objTaskService.GetFolder("\")
Set colTasks = objTaskFolder.GetTasks(0)
For Each objTask In colTasks
With objTask
If InStr(.Name, "GoogleUpdate") Then
objTask.Stop() << Wrong number of args or invalid property assignment
WScript.Sleep(10000)
objTask.Enabled = False << Working properly
objTaskFolder.DeleteTask objTask.Name,0 << Working properly
End If
End With
Next

The official documentation is located here: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382098(v=vs.85).aspx
RegisteredTask.Stop(ByVal flags)
Parameters
flags [in]
Reserved.
Must be zero.
Hence, it should be
objTask.Stop 0

Related

Reading REG_QWORD with VBScript?

I think the question speaks for itself. I have trouble getting some values out of the registry, and I was hoping someone around here might help me.
I'm stuck at IE9, as it is the only one which has some reasonable CSS capabilities, and does support GetObject().
So right now, lets say I'm trying to retrieve the memory size of a GPU at "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\HardwareInformation.qwMemorySize" (as far as I know, this should be a universal path & key).
This is where the problem begins. Either I get no output, or some error saying something is different, or what (my system is running in a different language so I cant offer the right translation).
After some research, I seem to have found the issue - the value I'm trying to read is REG_QWORD, and unfortunately I was only able to find very little covering this topic, and most of the solutions did not work for me.
So right now, I am with this code, which, unsurprisingly, also does not work (the code I had since like the beginning):
for Each oItem in colGPUs
memory = oItem.AdapterRAM / 1048576
If memory < 0 Then
If InStr(oItem.Name, "NVIDIA") Then
Set wssx = CreateObject("WScript.Shell")
msgbox CStr(wssx.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\000" + GPUID + "\HardwareInformation.qwMemorySize"))
End If
End If
Unfortunatelly it seems like there is no direct way of retrieving the value - within HTA itself.
I was able to get the value, however I did it using Powershell, executed the command, set its output to a specific file and read it.
Anyways, here is the actual solution I came up with specifically for this issue
wshell.Run "powershell (Get-ItemPropertyValue 'HKLM:\SYSTEM\ControlSet001\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000' 'HardwareInformation.qwMemorySize') | Out-File -FilePath C:\temp\gpu_mem.txt", 0, true
Set f = fso.OpenTextFile("C:\temp\gpu_mem.txt", 1, False, -1)
gpu_mem = CStr(f.ReadAll)
With this method Im directly obtaining the integer and passing it to the VBS

Delete a TestSet in ALM using OTA

So, I'm SLOWLY working my way to having a painful manual process automated in ALM using OTA. My current struggle is deleting a test set. It just doesn't do anything - no error, no deletion, nothing. It's like the line of code isn't even there. Although, it's definitely doing something cause ALM is working funky now.
I've tried different things: Delete, RemoveNode. Any advice is appreciated.
Set qcConnection = QCutil.QCConnection
Set tsFolder = qcconnection.TestSetTreeManager.NodeById(224)
Set tstestList = tsFolder.FindTestSets("", False, "")
If tstestList is Nothing Then
print "No manual tests present", vbOK
Else
For i = 1 to tstestList.Count
Set temp = tstestList.Item(i)
if temp.TestSetFolder.father.name = strMonth then
qcconnection.TSTestFactory.RemoveItem(temp.id)
end if
Next
End If
It seems you use a wrong factory - you need to use TestSetFactory instead of TSTestFactory

VBScript Nothing returns garbage

We have to use VBScript as an embedded script engine in our Hospital Information System.
When we use nothing to set the value of a control (textbox/checkbox/...) it worked always fine. Since somepoint it sets now the textbox to "?>".
item("TEXTBOX").value = nothing ' Leads to -> "?>"
It is not completly clear what causes this, maybe a windows update is responsible, every rollup ~ since KB3212646 Win7 2017-01 seems to cause this error.
My Question is now, has someone else also seem this error, so that it is clear that MS causes this error or is our HIS publisher responsible for not handling nothing correct.
I know setting a textbox to Nothing is not best practice instead "" should be better, but since the item object could be more the just a textbox e.g. a combobox/checkbox this seems, from an objectoriented perpsective, better. Or am I completly wrong?
Following #Ansgar comment, you should apparently change everywhere you have = nothing to = "" in your example
item("TEXTBOX").value = ""
Beware to keep the nothing if you have the Set keyword in left
Set some_object = Nothing

Cannot convert Group Description to String Variable

I have the following code:
Set objHoldGroup = GetObject("LDAP://" & objGroup)
strGroupDesc = (objHoldGroup.Description)
WScript.Echo(strGroupDesc)
The variable strGroupDesc returns nothing when echoed. I can output the description directly but I need it for further processing. Thoughts?
Explanation: Apparently your script sets Option Explicit (good), which you didn't tell us about (bad). This option makes defining variables before you can use them mandatory (good). Normally that would raise an "undefined variable" error, though. Since that doesn't seem to happen with your code, you seem to also have an On Error Resume Next somewhere in your code (very bad), which, again, you chose to keep quiet about (bad).
Next time please don't omit parts of your code that are vital for troubleshooting the problem. And don't use On Error Resume Next.
Issue found: I forgot to Dim strGroupDesc.

VBScript and presenting an input box

I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that
If its in 'debug' mode AND
The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)
then present an input box to allow me to type the date, time for logging in.
All other users would never see this and it would capture today with the system time.
I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.
You can use a command line parameter as Matt says to set the script into debug mode, eg
dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)
Which you can invoke with
wscript debugscript.vbs /debug
To get the current user name, you can use either the WMI Service or the WScript.Network object.
Once you have the username, you can conditionally throw up an InputBox and collect the value returned:
dim date_: date_ = Now()
if isdebug and username = "me" then
dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
' validate the input here
date_ = CDate(value)
end if
And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.
Most of this sounds like it can be resolved by the logic of the script.
Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).
For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...
HTH,
Matt
I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.

Resources