VB6 (Compiled) 7Zip Command Line causing Error 10 ("The Array is Fixed or Temporarily Locked") - vb6

The following line works perfect in the interpreter environment:
ShellExecute Me.hWnd, "open", "7z.exe", " -o" & PNG_Folder & " -y e " & PathFileName2 & Ext & ".gz", "C:\Program Files\7-Zip", vbNormalFocus
When I compile my program and run the .exe, i get the error 10.
Been banging my head trying to figure this one out.
Software environment is Windows 7 32 Bit (needed for an industrial environment).

It turned out not to be shelling to 7z.exe being the problem. It was an error generated from GPIB, via GLOBMGR.DLL, that VB could not handle. Any exit from any subfolder (i.e., EXIT SUB, EXIT FUNCTION), caused the compiled program to lock up.
err.clear did not work.
on error goto 0 did not work
Nothing I tried worked. Program worked great in the development environment but locked-up in compiled mode if a timeout error occurred on the GPIB bus.
I found a great new method of retrieving an image from a tek scope via the GPIB bus that is much faster and does not generate any timeout errors.
Other errors did not cause a problem.

Related

Windows Server 2003: Task Scheduler is not running successfully VBS file jobs

We have an old Windows Server 2003 r2 which is doing nothing but using the task scheduler and a VBS file to check and rename some regularly re-occurring data files. It is setup to run every hour using my credentials. If I "run" it while I'm logged on the task runs and completes correctly. When no one is logged on the task runs but completes with an 0x1 code, ie it failed.
I have checked the event logs and see nothing which I can identify as an error or failure. We believe that it was running successfully until about 6-8 months ago (yes, it was one of those set it up and forget it things and we have not been regularly checking it).
=================Additional Information===============
I ran assoc .vbs and got this output: .vbs=VBSFile
I'm not sure how to determine the user environment variables?
For the task I have tried both the vbs file and also a bat file containing the reference to the vbs file. Both run when I'm logged and both fail to complete successfully when I'm not.
Here is the vbs script:
Dim fso, file, recentDate, recentFile, theFile, myfolder, mypath
set fso = CreateObject("Scripting.FileSystemObject")
set recentFile = Nothing
mypath = "D:\TheFTP\Main\Camera\lobby"
set myfolder = fso.GetFolder(mypath)
For Each file in myfolder.Files
If (recentFile is Nothing) Then
set recentFile = file
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
set recentFile = file
End If
Next
fso.CopyFile mypath& "\" & recentFile.name, "D:\TheFTP\main\camera\cam3.jpg"
set recentFile = nothing
set fso = nothing
Here is the last bat file where I have piped the output to a file:
C:\windows\system32\cscript.exe c:\CopyWebCamFile.vbs > c:\debug.txt
Debug.txt output when I'm not logged on shows an error, see below, which is not there when I run it and am logged on:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
CScript Error: Initialization of the Windows Script Host failed. (The system cannot find the file specified.
=====================================================
More information, I added several Wscript.Echo statements to my script, before the first line, after the FOR loop and before the "copyFile" command. When I'm logged on I see all of the output in C:\debug.txt. When NOT logged on I see the same above error message, ie no Wscript.Echo output. This would see to indicate that it can not find my vbs file when I'm not logged on.
===========================
Still no happiness here. I moved and modified the .bat file to also output the contents of the script file:
type H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug2.txt
C:\windows\system32\cscript.exe H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug.txt
As before I get output to both .txt files when it runs while I'm logged on and nothing in debug2.txt and the usual messages in debug.txt when I'm not.
I'll fiddle with the antivirus settings, but I need to ask about that first. We are using Symantec SEP.
How can I check on the user environment variables?
====================
Maybe this will clarify my problem or suggest a solution??
Can you offer any ideas...RDK
First off we would like to thank LeeHarvey1 for his time and suggestions as we searched for the cause of this issue. In the end it was one of his suggestions that fixed the problem, but we still have no idea what caused it.
A reboot of the system cleared up all of the issues surrounding the task scheduler and running VB Scripts! We had considered his early suggestion, but discounted it as this server had only been up for a little over 3 months. Not excessive in our experience. However, when all else failed we elected to do that and "voila" it fixed the issue. We wish we knew what caused it but are now just happy we can move on to other things.
Thanks again LeeHarvey1....

VBScript says file doesn't exist when I just copied it

I have a script on a Server 2008 R2 VM which calls to the shell to robocopy a bunch of files into a local directory and then, several seconds later, checks if a certain 2.5 MB .msi exists. It kept returning false even though robocopy successfully completed and visible inspection reveals the file is there on time. I reproduced this bug on my local Windows 7 with a script:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshShell = CreateObject("WScript.Shell")
Dim file : file = "LargeFile.exe"
objWshShell.Run "xcopy ""..\" & file & """ .", 1, True
WScript.Echo "EXISTS: " & objFSO.FileExists(file)
LargeFile.exe is an executable around 7MB. I place it one directory above my script, execute the script, and it prints EXISTS: False. I ran the script several times with this result before some switch flipped and it started reporting True consistently.
It still happens intermittently on my VM. It will work correctly several times, I'll do something else for a few minutes, and when I come back it stops working again.
What's going on here? I need to use the shell for copying because the network is iffy and causes objFSO.CopyFolder() to crash.

hMailServer, triggers jar failed

I wrote a little VBscript that calls a JAR-file over a command-line.
When I double-click on the VBscript file it runs, as it should. I am logged in with a administrator account.
call testSub()
Sub testSub()
CreateObject("Wscript.Shell").Run "java -jar " & "c:\test\UntisSMTP_SMS.jar " & "aaaa ", 0, true
End Sub
but when hMailServer ( run as local system ) should call the jar, nothing happens and I get a error message
Script Error: Source: (null) - Error: 80004005
I googled the error and I found a hint that, the problem comes from not valid access rights
Is there a way, how hMailServer can start the jar ?
Many thanks in advance
WORKAROUND:
I didn't find a direct answer to my problem, but I wanna share my workaround-solution.
hMailserver can not run a command prompt line, even if the services runs under a administrator account. I didn't find out why.
So my solution was to write a VBscript that sends a HTTPPost with the E-Mailbody to a PHP script, then the PHPscript replace my JAVA Program.

Run a vbscript as an admin from itself (Nagios / NSclient)

I'll detail as much as I can so you can understand in which environment I'm working on and what I am trying to do.
I am using Nagios at work to monitor our servers. Each one of our Windows servers has NSclient++ installed on it. One of the many scripts Nagios' calling is check_updates.vbs; here 's how it goes if someone need to know:
On the Nagios' server side, we execute the following command:
/usr/lib/nagios/plugins/check_nrpe -H WindowsServerIpAddress -p 5666 -t 120 -c check_updates
When we execute that command, here is what's happening on the Windows Server:
By using the nscp service, it calls the following command, defined in the nsclient.ini file (into NSclient++ folder):
check_updates=cscript.exe //T:120 //NoLogo scripts\\check_updates.vbs
Then, it calls the check_updates.vbs script.
The local account on the Windows Server is the administrator one. We have changed nscp service's properties so that this service is called with another account, created especially for monitoring.
So, when we call the check_updates.vbs script directly on the Windows server (i.e locally), everything goes well, the script is working perfectly. But if we call it remotely, on the Nagios server, we have a simple (but deadly) error that says Permission denied.
That is why we are focusing on giving enough permissions to the monitoring-user.
After searching more and more and trying everything we could, I must say we're kinda lost right now.
The last solution I tried was to add these lines at the beginning of the script, to give the monitoring-user enough permissions to execute the script properly:
Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & _
WScript.ScriptFullName & """" &_
" RunAsAdministrator", , "runas", 1
End if
(I found this here)
When I use this, locally I get an [error notice*] but the script is working anyway. However, when I call the script remotely, I just have a timeout after 120s.
More info: UAC is disabled on the Windows server, and the monitoring-user has full access control on the NSclient++\scripts folder. Using the nscp service with the admin account is not the solution we are seeking for this matter.
So, am I missing something here ? Do you have any idea about this ?
Thanks for the help ! :)
[*error notice]: Invalid arguments, check help with cscript.exe check_available_updates.vbs -h
If UAC is off then it's not a UAC permission error therefore don't worry about runas.
It's also unlikely to be a file permissions problem (all admins are equal unless someone made it different).
What is likely is the different environments. You have an assumption that is true for the interactive user only. You need to log what is happening in your script (see wshshell.LogEvent(intType, strMessage [,strTarget])). If your script has
on error remove next
remove it.
Mapped drives are a problem. As are environmental variables and special folders.
Try using Runas command line command with various options (eg /env) to see if you can duplicate the behaviour.
Also run
cmd /c set > c:\set.log
and compare the output from the two ways of running it (ie with your client and direct).
Thanks for your answer Tony, I've tried your suggestions, but eventually we ended up getting around the problem.
Despite we gave the monitoring-user all permissions needed to execute this script, it was not working. So here's what we've done:
We created a bat file which contains the command-line to call check_update.vbs and to write its output into a new file:
cscript.exe //T:120 //NoLogo "C:\Program Files\NSClient++\scripts\check_updates.vbs" > "C:\Program Files\NSClient++\check_update.log"
Then, we've created a scheduled task (using the TaskScheduler) which calls the bat file every day to check for new updates.
To have the correct output in Nagios, we created another vbscript which only has to read the check_update.log file and return the appropriate value to Nagios:
Const ForReading = 1
Const rOK = 0
Const rWarning = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Program Files\NSClient++\check_update.log", ForReading)
FirstChar = objFile.Read(1)
Content = objFile.ReadAll
If FirstChar = "O" Then
Wscript.Echo FirstChar + Content
Wscript.Quit(rOK)
Else
WScript.Echo FirstChar + Content
End If
Wscript.Quit(rWarning)
This vbscript is really basic, since it only reads the first letter of the file to decide which value to return. Indeed, if there are no updates available, the message will always be "OK - No patches missing".
So, by calling the bat file using the SchedulerTask, we get around the fact that the monitoring-user has not enough permissions to execute the script.

Having difficulty running a program from my script

I'm struggling to run a program from my VBScript .vbs file. Substituting the line for a MsgBox works fine, so I know its definitely the "open program" line (oShell.Run("Release\My Application.exe")).
Anyway, this is a VBscript called start.vbs which is run from the root directory of a USB drive. It checks to see if .net framework 4.0 is installed and if it is then it should run My Application.exe (note the space... it might make a difference). My Application.exe is in a folder called Release.
As it is a USB drive I can't use explicit drive letters, eg: oShell.run("e:\Release\My Application.exe") although trying this also doesn't appear to work. Typing "e:\Release\My Application.exe" into a cmd window works fine, and runs the program as it is meant to work.
In the vbscript it just doesn't appear to do anything. Any reason?
Here is my code:
Option Explicit
Dim oShell
Dim value
On Error Resume Next
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKLM\SOFTWARE\Microsoft\.NETFramework\Policy\v4.0\30319")
If Err.Number = 0 Then
'Here I am struggling
oShell.Run("Release\My Application.exe")
Else
MsgBox("Version 4.0 of the .NET Framework is NOT installed.")
End If
I have commented above the line that doesn't work.
Thank you.
Not quite sure if this is the best answer, but I tried it and it work, so I'll just go ahead and post my idea.
I just used explorer.exe as a mediator and was able to open the file.
So the line that you're stuck with should probably become something like:
oShell.Run("explorer ""Release\My Application.exe""")
I tried it if it'll work in folder that is not in the System path and was able to open the executable.
Note : There may be better approaches.
Update: Thomas reported that the following code worked for him (the approach is better), the idea behind both approaches however is to quote the path (as you would do this in the Command Prompt, so filenames / folders with spaces in the path are properly resolved):
oShell.run("""Release\My Application.exe""")

Resources