Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

{NEED HELP} Executing .exe with params + Hotkeys

(VB6)

Hi its been years since I have last studied VB but now I've come to a problem (or rather a difficulty) I would like help solving. I run a computer lab at a school. The computers are on a LAN and my main problem is that students usually never turn off their computers when done. So I decided to implement the use of the built-in "Remote shutdown" function in windows XP. Now I would like to somehow implement this in a program. Heres how I aim for it to work.

This is the line that is going to execute the shutdown program:
Shell (C://****.exe -s -m //####sID)
The -m parameter is used to specify which computer on the network
I intend the integer "sID" to be the computer number - they are numbered from 00-30. (the first part of computer name is #### which should stay the same for all PCs in the room) My question is how make it so that I would only need to input #### at the start of the program and it will automatically set 31 buttons to execute the programs with sID increasing by one each time (i.e. button0-sID, button1-sID+1 button2-sID+2) I only want the #### part to be changeable by the user because this program is intended to be used in many classes.

Another thing is how would I set a specific hotkey to each button (i.e. button0- Ctrl+0.

I know this may be hard to understand but it was difficult to explain so please bare with me. Any help will be appreciated and I intend to include credits in the program. Thank you in advance
[1504 byte] By [aahost] at [2007-11-11 10:09:22]
# 1 Re: {NEED HELP} Executing .exe with params + Hotkeys
sorry but it is not clear to me...
You talk about "buttons" without explaining what they are
Secondly, you said that #### is not changeble, but later you said that you want it to be changeble...

As I undestood, you have 30 (or so) computers named foo01, foo02, fooo03 etc in una class, and 30 named goo01, goo02 etc in another class. Am i correct?

Why don't you use a TextBox to enter the common part of the name of the computers?
You can then build the computer names in a for loop
for k = 0 to ...
shell ...... computerName & format(k, "00") ...

Regarding HotKeys: the easy way is to set the KeyPreview of you form to True so you can intercept all the key events in the form KeyDown or KeyPress events.

Let me know,
Marco
mstraf at 2007-11-11 17:23:11 >
# 2 Re: {NEED HELP} Executing .exe with params + Hotkeys
I meant #### should stay the same for all PC's in a room. and yes you understood correctly. Buttons are basic commandbuttons.

Sorry its been so long since I touched VB that I have forgotten most of the syntax but what exactly is that variable you named "k" and how would I set up this loop. THanks!
aahost at 2007-11-11 17:24:11 >
# 3 Re: {NEED HELP} Executing .exe with params + Hotkeys
put this code in the Click event of a button used to shut down all computers

dim k as long
dim cmp as string

for k = 0 to 30 ''' whatever your computers numbers are
cmp = txtBox.Text & Format(k, "00") ''' build the computer name in a string
Shell(".... -m " & cmp)
next
mstraf at 2007-11-11 17:25:09 >
# 4 Re: {NEED HELP} Executing .exe with params + Hotkeys
Thank You I get much of it
Is it feasible to set the computer # as "sID" and have it in separate buttons too in case I wished to shut down specific PC's

For example.

Dim sID As Integer = 0

Private Sub Command1_Click()
cmp = txtBox.Text & sID+1
Shell(".... -m " & cmp)
End Sub

Private Sub Command2_Click()
cmp = txtBox.Text & sID+2
Shell(".... -m " & cmp)
End Sub

....3...etc

And also if its not too much would you elaborate on the use of hotkeys?
aahost at 2007-11-11 17:26:16 >
# 5 Re: {NEED HELP} Executing .exe with params + Hotkeys
if you have 30 computers, maybe it is a good idea to have a textBox also for the computer number and only two buttons: one to shutdown all pc's (with the for loop I gave you) and the other to shutdown only one, in the case

dim cmp as Sting
cmp = basenameTextBox & format(Cint(computerNumberTextBox.text), "00")
Shell(...) ' same as before

For the hotkeys, once you set the KeyPreview property of the form:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if shift = vbCtrlMask then
if keycode >= vbkey0 and vbkeycode <= vbkey9 then
dim cmp as string
cmp = basenameTextBox.text & format(keycode - vbkey0, "00")
...

in this way you intercept Ctrl+0, 1, 2,... so you can shut down only 10 computers... maybe you can use the standard keys for the others, using the same order they in the keyboard, that is q,w,e,r,...p for computers 11 to 20, a,s,d,...l,m for the rest
mstraf at 2007-11-11 17:27:15 >
# 6 Re: {NEED HELP} Executing .exe with params + Hotkeys
Thank you so much you are truly the expert. I seem to have recover part of my memory now. I will be sure to add your name (and dev-archive.com Forums) in the credits of the final product. Thanks again.
aahost at 2007-11-11 17:28:14 >
# 7 Re: {NEED HELP} Executing .exe with params + Hotkeys
you are very welcome, I am always glad to help
mstraf at 2007-11-11 17:29:18 >