Executing VBScript for disabling network adapters

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Executing VBScript for disabling network adapters

Post by stu »

I'm currently trying to deactivate network devices on demand from a Neobook application by using the following VBScript:

[syntax=vb]'===================================================
' VBScript: AUTHOR: Ed Wilson , MS, 5/5/2004
' NAME: <turnONoffNet.vbs>
' COMMENT: Key concepts are listed below:
'1.uses the c:\devcon utility to turn on or off net
'2.uses a vbyesNO msgBOX to solicit input
'3. KB 311272 talks about devcon and shows where to get
'====================================================

Option Explicit
Dim objShell
Dim objExec
Dim onWireLess
Dim onLoopBack
Dim turnON
Dim turnOFF
Dim yesNO
Dim message, msgTitle
Dim strText

message = "Turn On Wireless? Loop is disabled" & vbcrlf & "if not, then wireless is disabled and loop enabled"
msgTitle = "change Network settings"
onWireLess = " PCMCIA\Dell-0156-0002"
onLoopBack = " *loop"
turnON = "enable"
turnOFF = "disable"
Const yes = 6

Set objShell = CreateObject("wscript.shell")
yesNO = MsgBox(message,vbyesNO,msgTitle)

If yesNO = yes Then
WScript.Echo "yes chosen"
Set objExec = objShell.exec("cmd /c c:\devcon " & turnON & onWireLess)
subOUT
Set objExec = objShell.exec("cmd /c c:\devcon " & turnOFF & onLoopBack)
subOUT
Else
WScript.Echo "no chosen"
Set objExec = objShell.exec("cmd /c c:\devcon " & turnOFF & onWireLess)
subOUT
Set objExec = objShell.exec("cmd /c c:\devcon " & turnON & onLoopBack)
subOUT
End If

Sub subOUT
Do until objExec.StdOut.AtEndOfStream
strText = objExec.StdOut.ReadLine()
Wscript.Echo strText
Loop

End sub[/syntax]

Unfortunately I havent been able to overcome the following error on execution:

Image

Additionally. Does anyone care to explain how to execute a console comand from neobook... Maybe something like NET USER /DOMAN. Or even, if possible, execute a netcat instance with some parameters.

Regards!
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: Executing VBScript for disabling network adapters

Post by Neosoft Support »

I think you just need to remove the calls to Wscript.Echo. That command is intended to output a message on the console. Since NeoBook is a graphic mode app and not a console app you can't "echo" something to the screen. You can remove the Wscript.Echo commands entirely or replace them with MsgBox ("text").
NeoSoft Support
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

Neosoft Support wrote:I think you just need to remove the calls to Wscript.Echo. That command is intended to output a message on the console. Since NeoBook is a graphic mode app and not a console app you can't "echo" something to the screen. You can remove the Wscript.Echo commands entirely or replace them with MsgBox ("text").
Thanks!

What about using RUN command in NB for opening a console and executing a command:

sort of

CMD
NET USER /DOMAIN

Regards
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: Executing VBScript for disabling network adapters

Post by Neosoft Support »

You can experiment with the Run action. It might work as well.
NeoSoft Support
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

Neosoft Support wrote:You can experiment with the Run action. It might work as well.
I was into a way of executing accions for a cli application that kills tasks, some applications go to the system tray when you close them from CMD with traditional methods, uTorrent is an example. So PsKill.exe (http://ss64.com/nt/pskill.html) is the best option... i decided to include it into the end product and use a BAT file to call it:

Code: Select all

pskill.exe /accepteula uTorrent.exe
exit
I just use RUN from Neobook end of the day works as expected...

=)
mishem
Posts: 581
Joined: Mon Oct 08, 2012 1:51 pm

Re: Executing VBScript for disabling network adapters

Post by mishem »

There are plug-in to capture and redirect the output to the console application project.

dmCMDLine

Download.
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

mishem wrote:There are plug-in to capture and redirect the output to the console application project.

dmCMDLine

Download.
I dunno why but by using:

dmRun "C:\Windows\System32\cmd.exe" "netstat -a" "[NetstatResult]" "False" "False"

I get only the Windows version info, check it out:

Image
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: Executing VBScript for disabling network adapters

Post by Tony Kroos »

Check the sample pub for netstat.exe and cmd.exe usage.

setvar "[CMDApp]" "[SystemDir]netstat.exe"
setvar "[CMDLine]" "-a"
dmRun "[CMDApp]" "[CMDLine]" "[NetstatResult]" "False" "False"

setvar "[CMDApp]" "[SystemDir]cmd.exe"
setvar "[CMDLine]" "/c netstat -a"
dmRun "[CMDApp]" "[CMDLine]" "[NetstatResult]" "False" "False"

Also, did you create OnConsoleBuffer subroutine in your pub? It is triggered when the console displays new piece of data for reading.
In case it exists, [NetstatResult] will contain only currently reading block of console data at the current moment (when subroutine is triggered), you must implement your own actions to concatenate results. So you probably getting only last portion of output.
In case it doesn't exist, all console output will be placed in [NetstatResult] AFTER netstat.exe is finished so you won't get any output during execution. You have to wait, it may take minutes to get all connections stats.
Also note if you execute dmRun in parallel thread (first parameter is False, to avoid GUI freeze) OnConsoleBuffer is not used, so you just have to wait until netstat is finished to get the output.
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

Tony Kroos wrote:Check the sample pub for netstat.exe and cmd.exe usage.

setvar "[CMDApp]" "[SystemDir]netstat.exe"
setvar "[CMDLine]" "-a"
dmRun "[CMDApp]" "[CMDLine]" "[NetstatResult]" "False" "False"

setvar "[CMDApp]" "[SystemDir]cmd.exe"
setvar "[CMDLine]" "/c netstat -a"
dmRun "[CMDApp]" "[CMDLine]" "[NetstatResult]" "False" "False"

Also, did you create OnConsoleBuffer subroutine in your pub? It is triggered when the console displays new piece of data for reading.
In case it exists, [NetstatResult] will contain only currently reading block of console data at the current moment (when subroutine is triggered), you must implement your own actions to concatenate results. So you probably getting only last portion of output.
In case it doesn't exist, all console output will be placed in [NetstatResult] AFTER netstat.exe is finished so you won't get any output during execution. You have to wait, it may take minutes to get all connections stats.
Also note if you execute dmRun in parallel thread (first parameter is False, to avoid GUI freeze) OnConsoleBuffer is not used, so you just have to wait until netstat is finished to get the output.
sweet! works like a charm! Yet another plugin I did'nt have a clue about...

Thanks for your help
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Executing VBScript for disabling network adapters

Post by dpayer »

[quote="Tony Kroos"]Also, did you create OnConsoleBuffer subroutine in your pub? It is triggered when the console displays new piece of data for reading.
[/quote="Tony Kroos"]

The plugin looks very interesting but an even rudimentary translation would be helpful. I can't see from the dialogue box what the parameters are meant to be.

The .ru site is helpful when translated but not quite enough for me to grasp. Kudos to the developer.
David Payer
Des Moines, Iowa
USA
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

dpayer wrote:
Tony Kroos wrote:Also, did you create OnConsoleBuffer subroutine in your pub? It is triggered when the console displays new piece of data for reading.
[/quote="Tony Kroos"]

The plugin looks very interesting but an even rudimentary translation would be helpful. I can't see from the dialogue box what the parameters are meant to be.

The .ru site is helpful when translated but not quite enough for me to grasp. Kudos to the developer.
x2

It would be extremely nice if the Russian forum could include an English area. (?) Maybe just so people could ask about the plugins they have.
mishem
Posts: 581
Joined: Mon Oct 08, 2012 1:51 pm

Re: Executing VBScript for disabling network adapters

Post by mishem »

It would be extremely nice if the Russian forum could include an English area. (?) Maybe just so people could ask about the plugins they have.
Don't hesitate to ask at the Russian forum questions in any language.
Tony Kroos
Posts: 419
Joined: Thu Oct 15, 2009 3:43 pm

Re: Executing VBScript for disabling network adapters

Post by Tony Kroos »

Or you may ask here in Russian section (in case you cannot bypass registration)
User avatar
stu
Posts: 322
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Post by stu »

Cheers dudes, I had some trouble with the avatar thing... its all good now... DEMBEL plugins are pure gold, I have to say.
Locked