View Full Version : Using dos commands with buttons
mrdude
08-10-2006, 06:21 PM
OK I know I can do this with a batch file but can i use the following dos command with a button?
@netsh interface ip set address "Local Area Connection" static 192.168.1.2 255.255.255.0 192.168.1.1 1
I really want to make three input boxes so I can set ip details, ie ip address, netmask and gateway - then press a button to change my network card details.
Can I do this with apms or will I just need to use dos to do it? thanks.
yosik
08-10-2006, 11:28 PM
Hi,
Check this thread:
http://www.indigorose.com/forums/showthread.php?t=16511&highlight=cmd
Yossi
mrdude
08-11-2006, 08:20 AM
I got it to work like this:
ipconf.txt had the following info:
@netsh interface ip set address "Local Area Connection" static aaa.aaa.aaa.aaa bbb.bbb.bbb.bbb ccc.ccc.ccc.ccc 1
-----------------------------------------------------------------------
result1 = Input.GetText("Input1");
result2 = Input.GetText("Input2");
result3 = Input.GetText("Input3");
SourceFile = TextFile.ReadToString("AutoPlay\\Scripts\\ipconf.txt")
change1 = String.Replace(SourceFile, "aaa.aaa.aaa.aaa", result1, false);
TextFile.WriteFromString("AutoPlay\\Scripts\\ipconf.bat", change1, false)
SourceFile = TextFile.ReadToString("AutoPlay\\Scripts\\ipconf.bat")
change2 = String.Replace(SourceFile, "bbb.bbb.bbb.bbb", result2, false);
TextFile.WriteFromString("AutoPlay\\Scripts\\ipconf.bat", change2, false)
SourceFile = TextFile.ReadToString("AutoPlay\\Scripts\\ipconf.bat")
change3 = String.Replace(SourceFile, "ccc.ccc.ccc.ccc", result3, false);
TextFile.WriteFromString("AutoPlay\\Scripts\\ipconf.bat", change3, false)
File.Run("AutoPlay\\Scripts\\ipconf.bat", "", "", SW_SHOWNORMAL, false);
----------------------------------------------------------------------
Surely there must be a better way to do this without the need for changing strings in a txt file and having to write a batch file - can't I just use some command in apms to do this for me - those examples in the above post don't really let me know how to use the proper syntax and i can't get it to work properly using the command line option with a button because or the "Local Area Connection" part having the quotes in it.
Desmond
08-14-2006, 12:09 PM
I'm just thinking out loud here ...
Does command.com (cmd) allow you to pass a command to it as an argument?
If so, you could use File.Run, and pass your command as the arguments string.
Desmond.
TJ_Tigger
08-14-2006, 12:21 PM
I'm just thinking out loud here ...
Does command.com (cmd) allow you to pass a command to it as an argument?
If so, you could use File.Run, and pass your command as the arguments string.
Desmond.
Yes it does. For instance if you click on Start->Run and type the following.
cmd /c "ipconfig"
or
cmd /k "ipconfig"
The command window will then launch and execute what is contained in the quotes. the slash is for keep open or close.
HTH
Tigg
Desmond
08-14-2006, 12:38 PM
Hey, that's really neat! Super useful.
mrdude
08-16-2006, 01:23 PM
I'm just thinking out loud here ...
Does command.com (cmd) allow you to pass a command to it as an argument?
If so, you could use File.Run, and pass your command as the arguments string.
Desmond.
Tried that and it doesn't work because of the "Local Area Connection" part is already in quotes, however if you could post an example of what you mean I am sure that other apms forum users would find this info usefull.
I like apms and it can do alot of stuff - but surely it should be able to perfom basic tasks that dos can manage?
TJ_Tigger
08-16-2006, 01:56 PM
Try one or both of these
--Escape the quotes within the doublequotes
cmd /k "@netsh interface ip set address \"Local Area Connection\" static aaa.aaa.aaa.aaa bbb.bbb.bbb.bbb ccc.ccc.ccc.ccc 1"
--uses single quotes to enclose the doublequotes
cmd /k '@netsh interface ip set address "Local Area Connection" static aaa.aaa.aaa.aaa bbb.bbb.bbb.bbb ccc.ccc.ccc.ccc 1'
mrdude
08-17-2006, 06:52 PM
Try one or both of these
--Escape the quotes within the doublequotes
cmd /k "@netsh interface ip set address \"Local Area Connection\" static aaa.aaa.aaa.aaa bbb.bbb.bbb.bbb ccc.ccc.ccc.ccc 1"
--uses single quotes to enclose the doublequotes
cmd /k '@netsh interface ip set address "Local Area Connection" static aaa.aaa.aaa.aaa bbb.bbb.bbb.bbb ccc.ccc.ccc.ccc 1'
OK tried both of those but they don't work - any other ideas?
pssah
08-17-2006, 11:19 PM
Good
Thanks yosik
mwreyf1
08-18-2006, 01:26 PM
This is how I do it.
Hope it helps.....
lac = "\"Local Area Connection\""
cmd_args = "@netsh interface ip set address " ..lac.. " 192.168.1.2 255.255.255.0 192.168.1.1 1"
mwreyf1
08-18-2006, 01:29 PM
Sorry....left out some of the code.
Here it is again.
lac = "\"Local Area Connection\""
cmd_args = "@netsh interface ip set address " ..lac.. " 192.168.1.2 255.255.255.0 192.168.1.1 1"
File.Run("CMD.exe", "/c \"\""..cmd_args.."", "", SW_SHOWNORMAL, true);
TJ_Tigger
08-18-2006, 01:45 PM
Should be able to accomplish the same thing on one line like this
File.Run("CMD.exe", "/c \"@netsh interface ip set address \"Local Area Connection\" 192.168.1.2 255.255.255.0 192.168.1.1 1\"", "", SW_SHOWNORMAL, true);
or I would think this would work too
File.Run("CMD.exe", '/c "@netsh interface ip set address "Local Area Connection" 192.168.1.2 255.255.255.0 192.168.1.1 1"', "", SW_SHOWNORMAL, true);
The entire argument section is contained in single quotes to the doubles will be interpreted as literal double qoutes.
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.