well basically I have a bit of a problem and I'm at a block at the moment, I'm trying to use vbs to run a foxpro .prg file , normally I would have to right click the .prg then click run then foxpro ask me for the possessing date and stuff but i can use sendkeys for that i figured I don't mind if its not hidden any help will be greatly appreciated , thanks
If you can double-click the PRG file and it opens in FoxPro (meaning the PRG extension has a shell association with the FoxPro executable) then you should be able to use the Run method of VBScript's Shell object to "launch" the PRF file directly:
CreateObject("WScript.Shell").Run Chr(34) & strPathToPrgFile & Chr(34)
Otherwise, you could always launch FoxPro and pass the PRG file as a param:
CreateObject("WScript.Shell").Run Chr(34) & strPathToFoxProExe & Chr(34) & " " & Chr(34) & strPathToPrgFile & Chr(34)
Related
I have the maintenance of an old software written in VB6 that I have had to change from MSAccess to mySQL. The program works by calling external database utility programs which redirect data to and from files using the shell.
While trying to write the new database backup and recovery functions I got a terrible surprise. It seems the angle brackets do not work when sending a commandline through SHELL function (p.e.):
Shell ("""" & mySQLdumpLocation & """" --defaults-file="""" & confFileLocation & """" nameofthedatabase > """" & backuplocation & """")
This instruction opened a command line window where the mysqldump output could be seen but it did not create the backupfile. When copying the same instruction to a cmd window it worked perfectly.
I noticed after many hours looking for information that changing the ">" keyword to -r made the job.
Now I'm facing the same problem withe the recovery of the backup. In theory I need to use this:
Shell ("""" & mysqlexeLocation & """" --defaults-file="""" & confFileLocation & """" nameofthedatabase < """" & backuplocation & """")
...and no, it does not work. It does nothing. The same instruction copied to cmd window works as expected... and I haven't found a substitute for the "<".
Does anyone know what is happening?
we have this vbs script we use to update certain documents with SyncToy.
This is the script as it is currently written:
'--------------------------------------------------
Set oShell = CreateObject("WScript.Shell")
sFilePath = chr(34) & "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" &
chr(34) & "-R"
iRC = oShell.Run(sFilePath, 0, True)
' Return with the same errorlevel as the batch file had
Wscript.Quit iRC
'---------------------------------------------------
I didn't write this script, and I have very little experience with scripting.
I have a task set up in task scheduler that runs this script anytime the device connects to a network. The script should run SyncToy and then synchronize the folder pair that is set up. I have tried running the script through command prompt with the cscript command but nothing happens as far as I can tell. At least the folders aren't syncing.
The script is running on a Windows 10 pro tablet
I have verified that the task is indeed running when it is supposed to. I'm just not sure if it is an issue with the way the script is written or if the task settings need to be changed. Is there anything wrong with the script as far as you can tell?
I was unsure whether to post this here or over in serverfault. If this doesn't belong here please move the question over to serverfault
Update: I've verified that this isn't a problem with the script. This problem apparently arose only after the update from SyncToy 2.0 to 2.1.
Thanks Guys.
There is a error with the sFilePath lines.
First, I don't know if this was originaly on a single line but it should (or add "_" before changing line).
Then, this (...)& >"-R" would not work. The ">" symbole is outside the quotes and generate a error.
If you want to execute this command: "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" -R,
this is the way to do this:
sFilePath = chr(34) & "C:\Program Files\SyncToy 2.1\SyncToyCmd.exe" & chr(34) & " -R"
You can also add msgbox sFilePath to show a popup with the value of sFilePath.
To test/run the script, you just need to double-click on it.
I want to run a program (that is not in the same directory as the script) with a MSG box, here's the code (it doesen't work because it needs the program to be on desktop like the script)
puls = MsgBox("Want to open steam?", vbYesNo + vbQuestion)
if puls = vbYes then
CreateObject("WScript.Shell").Run "C:\Program Files(x86)\Steam\Steam.exe"
CreateObject("WScript.Shell").Run "C:\Users\Dario Loi\AppData\Local\TeamSpeak 3 Client\ts3client_win64.exe"
else
MsgBox "Okay :(", vbInformation
end if
now, as you can see, i want to execute this at system startup to get my gaming programs running, but i can't put steam on the desktop because it will dump it's assets there, and it would be a mess, i can't put the script in steam's directory too, same thing for TS3, also, i tried to replace the name of the file with it's path, but it does not work either
EDIT:
Just for making things clear, i've got a VBS File on my desktop, along with it, on the desktop i've got 2 links (not the original EXEs), to steam and TS, (the programs i want to run), i would want to open these 2 programs without putting the script and the program in the same folder, so
by making the script refer to the link and
by making the script refer to the path,
if you got ideas, please tell me
And if you try like this ?
puls = MsgBox("Want to open steam?", vbYesNo + vbQuestion)
Set ws = CreateObject("WScript.Shell")
if puls = vbYes then
ws.Run DblQuote("C:\Program Files(x86)\Steam\Steam.exe")
ws.Run DblQuote("C:\Users\Dario Loi\AppData\Local\TeamSpeak 3 Client\ts3client_win64.exe")
else
MsgBox "Okay :(", vbInformation
end if
'*****************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*****************************************
Add a cd (change directory) line to the full path of your executables which will bring the cmd prompt to that directory, and do your run command.
I want to open .mp3 files with mpg123.exe silently when a .mp3 file is double clicked from within Windows Explorer. For this I wrote a VBScript as bellow and changed the default program for playing .mp3 files by assigning my VBScript to it via Open with → Choose default program. My script is working well from within command line (cmd.exe) but when a .mp3 file is double clicked I get an error message that double clicked .mp3 file is not an executable file in Windows. Here is my VBScript, please let me know where I am doing wrong.
if Wscript.arguments.count = 0 then
WScript.quit
else
strSoundFile = WScript.Arguments.Item(0)
end if
Set objShell = CreateObject("Wscript.Shell")
strCommand = "mpg123.exe -q " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
Why don't you just associate mp3 files with mpg123.exe and set up the associated parameters (eg: -q "%1") instead?
Since I couldn't find a notable existing example, I've whipped up an example for you. (tested to work on Windows 7 with mpg123.exe). The response was too image heavy to post here. I hope it helps you.
Is it possible to call a .vbs script from a VBA code whenever needed? If possible then can you give me a sample code of how to do so?
To run a file:
Shell "wscript c:\null\a.vbs", vbNormalFocus
replacing wscript with cscript if the VBS wants to use the console.
Or you can add a reference to the Microsoft Script Control and interact with the VBScript runtime directly to execute VBS code, procedures etc;
Dim scr As ScriptControl: Set scr = New ScriptControl
scr.Language = "VBScript"
scr.AddCode "sub T: msgbox ""All Hail Cthulhu"": end sub"
scr.Run "T"
I only want to add to Alex' answer, that in some environments the object must be created in the following way:
set scr = CreateObject("MSScriptControl.ScriptControl")
If Alex adds this to his answer, I will delete this one.
Try somthing like this
ChDir ThisWorkbook.Path
Shell "wscript " & ThisWorkbook.Path & "\your.vbs", vbNormalFocus
It helped me.
You may want to use """ if your path name contains a - For me the following solved this issue:
Shell "cscript """ & ActiveWorkbook.Path & """\your.vbs", vbNormalFocus