?
Solved

Help with what should be a simple VB application 500 Points

Posted on 2008-11-18
8
Medium Priority
?
278 Views
Last Modified: 2012-05-05
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
Comment
Question by:ise438
  • 5
  • 2
8 Comments
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22987194
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
 
LVL 10

Expert Comment

by:3_S
ID: 22988542
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
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22988721
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:AmazingTech
ID: 22988757
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
 
LVL 10

Expert Comment

by:3_S
ID: 22988899
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
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22988934
You're correct sorry I was reading too fast and missed some important key points in your comments.
0
 

Author Comment

by:ise438
ID: 22992722
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
 
LVL 21

Accepted Solution

by:
AmazingTech earned 2000 total points
ID: 22995005
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question