Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help running a program at startup 3

Status
Not open for further replies.

jtcdesigns

IS-IT--Management
Oct 22, 2007
26
0
0
US
I have searched the internet via google for a solution to my problem and yet I have found nothing of use. I am trying to run a script that will run a data collection program on 10 computers. Currently I have the computer auto login when the computer boots and set the rights to power user. Upon start up the program will start and automatically login and open up. To do that I have set the username and password in the shortcut icon on the desktop. The trouble I am having is I found a script to run the program but it keeps coming up with errors from windows script host. Could someone help me out? Or direct me to where I can get tutorials on vbscript? It has been a few years since I have done any programming so I am feeling a bit rusty. Thanks.
 
You should post the script you are using and the error message you are receiving.
 
here is my code.

Option Explicit
Dim objshell
Set objshell = CreateObject("WScript.Shell")
objshell.run "c:\program files\EFI\PSI\psmain.exe"
WSCript.quit


The error states that it cannot find the file thought I know the path is correct. I think I may have the quotes wrong. I have tried double quotes around the path and I get no error but the program doesn't start.

 
ok I finally found a book of mine from when I used visual basic. I figured it out with this code.

Sub Run(ByVal sFile)
Dim shell

Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub

Run "C:\Program Files\EFI\PSI\psmain.exe"

The one thing I now have a question on is the program that launches asks for a user and password. I have a shortcut on the desktop on startup and when I launch it, it automatically logs in. Is there a simple way of doing this through a vbscript?

 

I found this code on the site although I don't recommend passing admin like credentials through a script as it's always in plain text and not encrypted. But if you have to you have to:

Code:
Option explicit 

Dim oShell 

set oShell= Wscript.CreateObject("WScript.Shell")

'Replace the path with the program you wish to run c:\program files...

oShell.Run "runas /noprofile /user:administrator ""wscript.exe C:\test.vbs"""

WScript.Sleep 1000

oShell.Sendkeys "passwordhere"
WScript.Sleep 1500
oShell.Sendkeys "{ENTER}"

Wscript.Quit
 
This is actually just a data collection program with a standard username and password. The program doesn't need admin credentials to run. It starts up and then has username and password boxes and then the login button. My shortcut Icon seems to do the trick but I would rather have a script to do this for when we replace the machines in the future I dont have to go to each computer to add in the icon.
 
I tried your code and it will actually help me with another project I have with running some reg files as admin on those computers... but thats a later thought. My shorcut goes as follows...


Target: "C:\Program Files\EFI\PSI\Psmain.exe" "user=user, password=, company=1"

I tried to add that second set of quotes with the user and password etc but got an error because obviously I dont think I am allowed to just add that code to the end without some statement. I appreciate your help. Google apparently can only do so much. I found this place to be very helpful while I stumbled upon it and it helped me with other issues in vbscript.
 
Unfortunately, it's not my code however, I was happy to look it up for you. Using the search feature you can find lots of different snippets. Also, I highly recommend reviewing the site FAQ's as they are chalked full of helpful information.
 
Thanks for the help. I probably shouldn't have quit programming 5 years ago. I will search the site though. I also need to figure out how to kill the explorer.exe task at startup so all the user can do is have access to the one program.
 
shell.Run """C:\Program Files\EFI\PSI\Psmain.exe"" ""user=user, password=, company=1""", 1, False

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
try doing it the old DOS way, it should work

wshshell.run "cmd /c "C:\Progra~1\EFI\PSI\Psmain.exe",0,True
 
PHV, I tried the code but it didn't work. Thought I think it would if I did the rest of the code right. It is possible I dont have something right. my code as follows

Sub Run(ByVal sFile)
Dim shell

Set shell = CreateObject("WScript.Shell")
shell.Run """C:\Program Files\EFI\PSI\Psmain.exe"" ""user=user, password=, company=1""", 1, False
Set shell = Nothing
End Sub

Run "C:\Program Files\EFI\PSI\psmain.exe"


GrimR, I'd try it the DOS way but I need to get the user and password involved to.
 
ok nevermind I figured it out and got it working. I did objshell and didn't run it in a sub. Now that it works I need to look up pressing keys upon launch. When the app opens up if you press alt + m it opens the module menu then you press D and then press D again and it opens up the data collection window. I believe I seen it before in vbscript to press certain keys so I will give it a shot. thats all for the help. If you know anything about this new problem let me know. thanks.
 
This is the code I used

option explicit
Dim objShell
Dim oShell
Set objShell = CreateObject("WScript.Shell")
objShell.run """C:\Program Files\EFI\PSI\Psmain.exe"" ""user=user, password=, company=1""", 1, False
WScript.Quit

before the WScript.Quit I tried to add in oShell.Sendkeys "[D]" just to see if I had the code right but it came up with an error Object Required: "

I am not sure how to fix this but I do know I will need to add in a sleep command like Wscript.sleep 1500 because you cannot press any keys until the app is up. Maybe I am doing the send key thing wrong? I need to do some google searching to figure out what to do for alt + M then D D
 
to stop confusing yourself I always use WshShell
you are using objShell and oShell so change oShell.Sendkeys to objShell.Sendkeys
 
nevermind that question. had a slight brain fart. I'm still looking for a way to send the alt + M key combo right now.
 
Like this

option explicit
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.run """C:\Program Files\EFI\PSI\Psmain.exe"" ""user=user, password=, company=1""", 1, False
WshShell.Sendkeys "D"

You may also want to look into AppActive Method
WshShell.AppActivate

and I always use
Dim objFSO [for ]
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
I'll give it a try and let you know. Do you know how I could do alt + m together ?
 
Everything works fine except if I do that dim statement on objFSO [for ]

I even took out the space within the brackets and got the same error of expected end of statement.

After removing that line of code I got an error on AppActivate saying wrong number of arguments or invalid property assignment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top