Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


convert .vbs to Visual Basic - take two

 
Logged in as: Guest
arrSession:exec spGetSession 2,7,49143
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> convert .vbs to Visual Basic - take two
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 convert .vbs to Visual Basic - take two - 7/7/2007 11:17:26 AM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
Hi Scripters!

I pieced together a script from many online examples which takes care of several obstacles that I encounter on my employer's domain when attempting to offer Unsolicited Remote Assistance, and I'd like to make it a lot prettier. I am interested in displaying a GUI to the technician that has check marks for each of the steps. I have the front-end working fine (a simple window with an input box and 4 checkmarks), but I was disappointed to learn that .vbs code isn't compatible with VB.NET. I'm looking to convert a few of the following functions into valid VB.NET code:

This portion queries the user to enter a computer hostname, and then runs psexec to add a localgroup called techSupportGroup to the Administrator's group:

      
I'm sure there exists a better method to add a name to a localgroup on a remote PC rather than psexec, but I don't know where to look to find the syntax.

Another branch of the code stops a service, performs a command-line execution, then resumes the service:

      
Again, I am attempting to replace the psexec portion of the code with standard VB.NET functions.

If anyone has some ideas, I'd be grateful to being pointed in the right direction. I'm also eager to share the completed code (after I add some error-checking) in the code forum.

Thanks,
Mike
 
 
Post #: 1
 
 RE: convert .vbs to Visual Basic - take two - 7/9/2007 6:42:59 AM   
  Rischip


Posts: 402
Score: 2
Joined: 3/26/2007
Status: offline
There is no need for VB.NET unless that is what you want in the end.
To do a purely vbscript WMI implementation to add the group. You would do this....
Using WMI to do remote execution is completely silent on the remote box. (You cannot make it visible)


      

_____________________________

Rischip
Author of - The Grim Linker

(in reply to itismike)
 
 
Post #: 2
 
 RE: convert .vbs to Visual Basic - take two - 7/9/2007 4:20:00 PM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
Hi Rischip,
Thanks for the informative reply!

True, I don't need it to be VB.NET - I was just trying to add more options to the script. Is there a method in .VBS to add checkmarks to an input box?

Secondly, I was wondering if you could give me some guidance/direction to understand some of the WMI codes here. Would you mind inserting some comments in the code or pointing me to a good resource that will help me understand some of the techniques you used in this example?

Thanks very much,
Mike

(in reply to Rischip)
 
 
Post #: 3
 
 RE: convert .vbs to Visual Basic - take two - 7/10/2007 1:58:54 AM   
  Rischip


Posts: 402
Score: 2
Joined: 3/26/2007
Status: offline
This should help

http://msdn2.microsoft.com/En-US/library/aa389763.aspx

http://www.computerperformance.co.uk/vbscript/wmi_process_start.htm


http://www.google.com/search?q=remote+execute+wmi&hl=en&safe=off


Check marks in an input box ?? I'm not sure what you mean, but I would initially say no.
If you want anything more than straightup text entry or the use of standard buttons, then you need to move to .HTA or create activeX InternetExplorer.Application and read back the forms control values.

< Message edited by Rischip -- 7/10/2007 2:06:45 AM >


_____________________________

Rischip
Author of - The Grim Linker

(in reply to itismike)
 
 
Post #: 4
 
 RE: convert .vbs to Visual Basic - take two - 7/11/2007 1:51:30 AM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
Ok, I can live without the checkboxes.  I'm still trying to decode the rest of your suggestion.  Sorry - I'm a bit of a newbie with WMI commands.

Your suggestion about prompting for a password is what I'm working on next.  Does a method exist that would conceal the password as it was typed?  I'm of the firm belief that I should NEVER see my admin password in plain-text during routine use.

(in reply to Rischip)
 
 
Post #: 5
 
 RE: convert .vbs to Visual Basic - take two - 7/11/2007 3:23:44 PM   
  Rischip


Posts: 402
Score: 2
Joined: 3/26/2007
Status: offline
If you are going to run the script using cscript (console) you can use


      

Otherwise you can use a password box in an HTA if you desire to create a gui for the app.
Enter Password<input type="password"></input>

_____________________________

Rischip
Author of - The Grim Linker

(in reply to itismike)
 
 
Post #: 6
 
 RE: convert .vbs to Visual Basic - take two - 7/11/2007 11:50:03 PM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
I think this is exactly what I'm looking for (or close enough :)  )

I did some searching for "ScriptPW.Password" and found a more detailed explaination of it's use on "The Scripting Guy's" site.   As you hinted at, I cannot do this in an Input box, so I'll need to open a console first.  I'm looking at other code and it looks like this is what opens a console:


      
where /C will close the console when the command is complete.  So how would I piece these code segments togther to get the desired results?

Desired results:
A console opens and says: "Please enter the administrator password for the target computer and press [Enter]"
The user enters a string, presses enter, and the console closes, while pswd contains the value of the password for use in the next code segment.

(in reply to Rischip)
 
 
Post #: 7
 
 RE: convert .vbs to Visual Basic - take two - 7/13/2007 12:09:32 AM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
Still trying to insert this into my script.  The rest of the script is running from a .vbs file that is executed from a double-click, so it's running from the WScript service - not CScript.  When I try to impliment the code above into the script, it generates object errors:

      

(in reply to itismike)
 
 
Post #: 8
 
 RE: convert .vbs to Visual Basic - take two - 7/13/2007 3:52:06 AM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
OK i am now using the 'Force script to run in CScript' from the FAQ page.  It runs correctly (after adding some Chr(34) around the pathname) and is an adequate solution.

Last difficulty is restarting the sessmgr service, and running the following command on the remote PC:


      
I was using psexec to accomplish this, but if I can do it without psec, the script will be MUCH more user-friendly.

Thanks very much for your help so far!
-Miike

< Message edited by itismike -- 7/13/2007 4:39:58 AM >

(in reply to itismike)
 
 
Post #: 9
 
 RE: convert .vbs to Visual Basic - take two - 7/14/2007 1:01:19 PM   
  Rischip


Posts: 402
Score: 2
Joined: 3/26/2007
Status: offline
well you should be able to run any command remotely using the method in the first post. It will however be invisible.
If you are just looking to start a service, use the SC command, should be native in XP, might need a resource kit for 2K or below.


_____________________________

Rischip
Author of - The Grim Linker

(in reply to itismike)
 
 
Post #: 10
 
 RE: convert .vbs to Visual Basic - take two - 7/14/2007 1:33:06 PM   
  itismike

 

Posts: 42
Score: 0
Joined: 7/7/2007
Status: offline
Thanks for the reply. I've learned much in the past few days, and am nearly ready to post the complete code on the forum. I ended up breaking one very long script into about 12 individual subroutines, and hope the modularity will help me and others reuse this code to create more useful scripts.

One thing I am unclear about and am still researching is how subroutines or functions within a .vbs script handle returning a variable. It looks like the only difference between a subroutine and a function is that a function can be declared as a certain type, and through this naming convention it will return a value:

      

So the above will set the value of 'return_variable' to the result of the function. Is this how it would be implemented?:

      

Do I need to declare a variable type or anything?

(in reply to Rischip)
 
 
Post #: 11
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> convert .vbs to Visual Basic - take two Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts