Solved

VBS script help needed

Posted on 2013-11-13
7
697 Views
Last Modified: 2013-12-10
I have the following vbs code.

The first one imports a key and the second one terminates a process.

I need the first part of the script to finish in order for the second one to execute. Can someone help out with that?

----------------------------------

On error resume next

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd /K CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
Set oShell = Nothing


strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
0
Comment
Question by:llarava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 50

Expert Comment

by:Rgonzo1971
ID: 39644942
Pls try
const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set oShell = WScript.CreateObject("WScript.Shell")
command = "cmd /K CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
oShell.Run command, DontShowWindow, WaitUntilFinished

Open in new window

Regards
0
 

Author Comment

by:llarava
ID: 39645041
Hi,

The code opens the app then does the import of the key but then the app does not get closed.
I need the app to get closed after the key is imported.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39645141
Change the CMD /K to CMD /C, that will have it close when finished.

~bp
0
Independent Software Vendors: 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!

 

Author Comment

by:llarava
ID: 39645185
Here is the new code with the CMD /C - The app does not get closed.

const DontWaitUntilFinished = false, ShowWindow = 1, DontShowWindow = 0, WaitUntilFinished = true
set oShell = WScript.CreateObject("WScript.Shell")
command = "cmd /C CD C:\Program Files (x86)\GNU\GnuPG\ & kleopatra.exe -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp"
oShell.Run command, DontShowWindow, WaitUntilFinished
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 39645248
It may be then that the kleopatra.exe program isn't designed to exit after processing the command line parms.  Does it bring up the UI for that application when you run this test?

~bp
0
 

Author Comment

by:llarava
ID: 39645264
Yes the UI shows and and the command is executed, however the app does not exit.

This is why I wanted to execute this code:

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39645686
Then you need to start the kleopatra process without waiting for it to end, wait a bit, end then end the process again. Using cmd.exe should not be necessary.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run Chr(34) & "C:\Program Files (x86)\GNU\GnuPG\kleopatra.exe" & Chr(34) & " -i --import-certificate z:\255BD8BE19698491D80EA01A525F26535092FC41.pgp", 1, False
Set oShell = Nothing
Wscript.Sleep 5000

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Kleopatra.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

Open in new window

0

Featured Post

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!

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

696 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