0

Is it possible to include in a VB.net 2008 Project a VBScript (test.vbs) and run it if its while the processing necessary? But the main thing is it should be possible to BUILD just one .exe.

If so, can you also receive values / arguments from the VBS file?

Here is an example, although it's pointless, but it is used for unterstanding:

  1. VB.net -> exe is running
  2. the exe runs please_find_the_coputername.vbs
  3. The script please_find_the_coputername.vbs -> obtained the computer name and sends this variable to VB.net
  4. VB.Net displays the computer name via Msgbox().

Note: I know that I can read out the computer name with VB.net but this example is only for understanding my questions.

Edit:

HI @maxedev thank you for your answer. Wow.. its nice trick. But I want only to do this VBScript code in VB.net:

Dim strComputer

strComputer = "LP-BKR"

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
  Wscript.Echo "Logged-on Domain: " & objComputer.Domain
  Wscript.Echo "Logged-on UserName: " & objComputer.UserName
  Wscript.Echo "Logged-on ComputerName: " & objComputer.Name
Next

set objWMIService = Nothing
set colComputer = Nothing

I searched the whole day to get the same Value... but didn't find anything. That's why I decide to do that in this way. But if I think, the trick with clipboard is risky. It pushes the still clipboard text away. How can I realize it?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Bk_
  • 99
  • 9

3 Answers3

1

I'm not sure exactly what you're trying to accomplish, but you could write to a text file and then read it through vb.net - or you could do something like this post to use the clipboard to pass info ie :

VBS:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c echo hello world | clip", 0, TRUE

VB.NET:

MessageBox.Show(Clipboard.GetText)

--shows "hello world"

Community
  • 1
  • 1
maxedev
  • 941
  • 8
  • 18
0

One solution would be to add a reference to the MS Script Control: http://msdn.microsoft.com/en-us/library/aa227400(v=vs.60).aspx

Using that, you can add literally add code (VBScript) with the AddCode() method then run it and get the output back. I have a tiny example here.

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
0

Windows automatically provides the information you're looking for in environment variables:

%USERNAME%      -> username of the logged in user
%USERDOMAIN%    -> WINS name of the domain the user is logged into
%USERDNSDOMAIN% -> FQDN of the domain the user is logged into
%COMPUTERNAME%  -> hostname of the computer
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328