Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert VBS to VB6

Status
Not open for further replies.

gbargsley

MIS
Nov 2, 2004
44
0
0
US
I have this VB Script file and was wondering how I can incorporate it into a Visual Basic 6.0 application.

VBS
------------------------------------------------------------
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "NTFOODDOM"
strPassword = "nwtester"
strUser = "okok"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
 
Open a new project, delete the form, add a module, create a Sub Main, put the global variable declarations outside the Sub Main, and the code inside. Compile and use. I know this is just the basics, but it should give you enough info to get started.

Lee
 
That's roughly about it.

However, if this is a CScript today and you need it to continue working from a command prompt see faq222-5647 for information on creating VB6 console applications.

Remember that VB has deployment issues too, though most recent of Windows probably do have the VB runtimes installed already. Thus you might be able to get away with just XCopy-deploying the compiled EXE as long as you don't use any special ACtiveX controls when you convert it to VB.
 
Er... I meant to say "recent versions of Windows probably do have" above. Sorry.
 
I dont't quite understand "trollacious" post.

Lets say I am adding this function to an existing VB Project that has a form.

I add a module and put all the above VBS code in it.

Where do you "put the global variables declarations outside the Sub Main" and what would they be?

And where would "the code inside" go?
 
You want to convert a WSH script to a VB forms program?

When do you want the (former) script logic to run? When a button is clicked?

No standard module, no [tt]Sub Main()[/tt] in that case.

Just add the button, then in the button-click event handler insert your script. You may want to move those [tt]Const[/tt] declarations to the top of the form module, as form-level global items.
 
I dimmed all of the variables, but I was not sure what data type ReturnValue should be. Any ideas??

Also, do you think I need to add any References or Components?

 
Not sure about ReturnValue. What is it and what are you going to do with it? Is it a return code (as in success/error)? If so, perhaps it ought to be a Long?

Looks like it is a [tt]uint32[/tt], so a Long may be your best bet - but a Variant should do fine. That's what it was as script.

If you are using late-binding (as in the script) for everything you may not need any references.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top