Help with what should be a simple VB application 500 Points

I have to design a simple program that does the following...

I need to know how to launch a program and insert reg keys using VB code.

I will probably use option boxes...

In english something like this..

If OptionBox1 = ture then
run this program (taskkill /IM tpstwnd.exe)
Insert this reg Key regedit /s "\\wanfs\Tech\DD\REG\1.REG"
and run this program TpstWnd.exe
Else
run this program (taskkill /IM tpstwnd.exe)
Insert this reg Key regedit /s "\\wanfs\Tech\DD\REG\2.REG"
and run this program TpstWnd.exe
End If
 
Can this be done ?

Ian.
Ian PriceIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AmazingTechCommented:
Try this.
Set wshShell = WScript.CreateObject ("WSCript.shell")
 
If OptionBox1 = true then
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\\wanfs\Tech\DD\REG\1.REG""", 0, True
wshShell.run "C:\Program files\TpstWnd.exe", 0, False
Else
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\\wanfs\Tech\DD\REG\2.REG""", 0, True
wshShell.run "C:\Program files\TpstWnd.exe", 0, False
End If
  set wshShell = nothing  

Open in new window

0
3_SCommented:
In VB6 you can not use the build in shell function for this.  (it's does not wait until the program is ended)
You need a shell and wait function
http://www.vbaccelerator.com/home/vb/code/libraries/Shell_Projects/Shell_And_Wait_For_Completion/article.asp


If OptionBox1 = True Then
    Call ShellAndWaitForTermination("taskkill /IM tpstwnd.exe")
    Call ShellAndWaitForTermination("regedit /s ""\\wanfs\Tech\DD\REG\1.REG""")
    Call ShellAndWaitForTermination("C:\Program files\TpstWnd.exe")
Else
    Call ShellAndWaitForTermination("taskkill /IM tpstwnd.exe")
    Call ShellAndWaitForTermination("regedit /s ""\\wanfs\Tech\DD\REG\2.REG""")
    Call ShellAndWaitForTermination("C:\Program files\TpstWnd.exe")
End If

Open in new window

0
AmazingTechCommented:
It does work in VB6 but there create object should be this instead of what a posted previously.
Set wshShell = CreateObject ("WSCript.shell")
 
If OptionBox1 = true then
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\\wanfs\Tech\DD\REG\1.REG""", 0, True
wshShell.run "C:\Program files\TpstWnd.exe", 0, False
Else
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\\wanfs\Tech\DD\REG\2.REG""", 0, True
wshShell.run "C:\Program files\TpstWnd.exe", 0, False
End If
  set wshShell = nothing  

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AmazingTechCommented:
Try it out. It does wait.
Private Sub Form_Load()
Set wshShell = CreateObject("WSCript.shell")
 
wshShell.run "regedit", 1, True
MsgBox "Hello! You see I waited until you closed Regedit."
Set wshShell = Nothing
 
End Sub

Open in new window

0
3_SCommented:
AmazingTech you are wright.  But I meant the built-in shell of VB6.  You don't use the VB6 built-in shell and yes you code will work also.
0
AmazingTechCommented:
You're correct sorry I was reading too fast and missed some important key points in your comments.
0
Ian PriceIT ManagerAuthor Commented:
Hi..

I used AmazingTech code and it works great apart from it won't relaunch the application when it get to line 6 or 10 depending on the option box choice.

This is the exact code I used and I have attached a screen dump in a word doc of the error I am getting..

Cheers

Ian

Private Sub Command1_Click()
Set wshShell = CreateObject("WSCript.shell")
 
If Option1 = True Then
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\\fs1\DD\Code\ARW2.REG""", 0, True
wshShell.run "C:\Program Files\Olympus\DSSPlayerPro\TpstWnd.exe", 0, False
Else
wshShell.run "taskkill /IM tpstwnd.exe", 0, True
wshShell.run "regedit /s ""\fs1\DD\Code\JAN.REG""", 0, True
wshShell.run "C:\Program Files\Olympus\DSSPlayerPro\TpstWnd.exe", 0, False
End If
  Set wshShell = Nothing
error.doc
0
AmazingTechCommented:
For some weird reason it needs quotes for the path with spaces.

wshShell.run """C:\Program Files\Olympus\DSSPlayerPro\TpstWnd.exe""", 0, False

Do you really want to run this hidden? Change the number if you want to see this app.

0 = Hidden
1 = Normal
2 = Minimized
3 = Maximized
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.