Source language: Translate to:

Executing VBScript for disabling network adapters

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Executing VBScript for disabling network adapters

Postby stu » Fri Aug 21, 2015 10:32 am

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

Syntax: [ Download ] [ Hide ]
Using Visual Basic Syntax Highlighting
'===================================================
' 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
Parsed in 0.007 seconds, using GeSHi 1.0.8.10


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!
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby Neosoft Support » Fri Aug 21, 2015 12:07 pm

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
Neosoft Support
NeoSoft Team
 
Posts: 5605
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Executing VBScript for disabling network adapters

Postby stu » Fri Aug 21, 2015 12:15 pm

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
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby Neosoft Support » Fri Aug 21, 2015 5:22 pm

You can experiment with the Run action. It might work as well.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5605
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Executing VBScript for disabling network adapters

Postby stu » Fri Aug 21, 2015 5:34 pm

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...

=)
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby mishem » Sat Aug 22, 2015 10:24 pm

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

dmCMDLine

Download.
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Executing VBScript for disabling network adapters

Postby stu » Fri Aug 28, 2015 4:29 am

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
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby Tony Kroos » Fri Aug 28, 2015 8:13 am

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.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: Executing VBScript for disabling network adapters

Postby stu » Fri Aug 28, 2015 9:59 am

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
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby dpayer » Mon Aug 31, 2015 10:37 am

[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
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Executing VBScript for disabling network adapters

Postby stu » Mon Aug 31, 2015 12:47 pm

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.
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Executing VBScript for disabling network adapters

Postby mishem » Mon Aug 31, 2015 6:24 pm

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.
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Executing VBScript for disabling network adapters

Postby Tony Kroos » Mon Aug 31, 2015 11:36 pm

Or you may ask here in Russian section (in case you cannot bypass registration)
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: Executing VBScript for disabling network adapters

Postby stu » Tue Sep 01, 2015 5:01 am

Cheers dudes, I had some trouble with the avatar thing... its all good now... DEMBEL plugins are pure gold, I have to say.
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest