• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

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.
0
Ian Price
Asked:
Ian Price
  • 5
  • 2
1 Solution
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now