Solved

VBS script help needed

Posted on 2013-11-13
7
711 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 51

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 55

Expert Comment

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

~bp
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 55

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 85

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

724 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