logo Sign In

Visual Basic Programming

Author
Time
Anyone have any programming experience in VB 6? Need an API call to shutdown a machine on command. I'm working on a login script that offers the terms for using our systems, and has an "I accept" and an "I don't accept" button on it. If they don't accept, they pop up a message telling them they're not authorized and I want it to shut the machine off.

A. Is this possible?
B. Any clue on implementation?
Nemo me impune lacessit

http://ttrim.blogspot.com
Author
Time
Hmn. Good question. I belive you would need a lower level programmed API, perhaps C? This would require a direct OS call, I belive, and VB6 is good for making cute little forms filled with textbox1, textbox2, and such. Now, if you dig deep, you might find some library with such system call to do it, but I don't know, I never needed such a thing. If I ever needed the computer to restart, I'd show a message asking for the user to do so, and never do it on my own. Never surprise the user, specially if it's a bad surprise like suddenly booting.

Bonus points: make a library on assembly. Why, x86 programming is lots of fun!

EDIT: Ahh ok sorry, I belive I didn't read it fully. But... a login script on VB6? When will it show up? How are you going to start the process?
“Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country.” — Nazi Reich Marshal Hermann Goering
Author
Time
A. Yes, it is possible.

B. I haven't seen a VB6 implementation, but I do have VBScript and C# implementations for it at work. (The C# one would be very easy to rewrite in VB.NET.) They both use the Windows Management Inteface, the Win32Shutdown command in particular.

With the way you're talking about it, I'd use the VBScript version because in Windows, you can specify a logon script that runs before the desktop gets loaded, i.e. right after the user logs on. I haven't done any GUI stuff in VBScript, but I can give you the functional code.

If you go with VB6 or .NET, you'll have to rely on a start up entry in the Registry or the Startup group under All Programs. GUIs for those are easy (and you can capture when they click on the X).

If you want the code, send me an e-mail at the address in my profile. I won't be in to work until Monday (I'm at a mind-numbing class right now), so I'll get it to you as soon as I can.
For a change, Lady Luck seemed to be smiling on me. Then again, maybe the fickle wench was just lulling me into a false sense of security while she reached for a rock. - The Icarus Hunt by Timothy Zahn
Author
Time
while im sure what dpk5e7 is saying answers the question (i havent used those commands myself), and is probably a very simple way to do it, ill offer what was my first thought when i read the question anyway.

it should be pretty easy to exec an external command, all you need to do is exec shutdown, using the command shutdown -s

if you type shutdown or shutdown ? in a command prompt it will give you all the switches you can use with it. for example you can set a delay (believe the default is like 30 seconds if you just do -s, you can also have it reboot -r or, my favorite, you can remotely shutdown a computer on the network using -m \\computername (good times unfortunatly the message says where the command came from, but still can be fun )

-Darth Simon
Why Anakin really turned to the dark side:
"Anakin, You're father I am" - Yoda
"No. No. That's not true! That's impossible!" - Anakin

0100111001101001011011100110101001100001

*touchy people disclaimer*
some or all of the above comments are partially exaggerated to convey a point, none of the comments are meant as personal attacks on anyone mentioned or reference in the above post
Author
Time
Originally posted by: Darth Simon
while im sure what dpk5e7 is saying answers the question (i havent used those commands myself), and is probably a very simple way to do it, ill offer what was my first thought when i read the question anyway.

it should be pretty easy to exec an external command, all you need to do is exec shutdown, using the command shutdown -s

if you type shutdown or shutdown ? in a command prompt it will give you all the switches you can use with it. for example you can set a delay (believe the default is like 30 seconds if you just do -s, you can also have it reboot -r or, my favorite, you can remotely shutdown a computer on the network using -m \\computername (good times unfortunatly the message says where the command came from, but still can be fun )

-Darth Simon


That is quite a good way to do it.
“Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same in any country.” — Nazi Reich Marshal Hermann Goering
Author
Time
I agree, the shutdown command will work... depending on how locked down the operating system is. If I remember correctly, there's a setting in the Local Computer Policy that can restrict everyone (even Admins) from using that command. My network at work is locked down like that (it has to be if you want to pass a certain government agency's inspection). I use my code to remotely shutdown/reboot/log off computers on my network from a web interface. This will work if a certain port on the computer isn't blocked (snmp, I think. We're not allowed to have host based firewalls).

And yes, you can exec an external command from almost any programming language.
For a change, Lady Luck seemed to be smiling on me. Then again, maybe the fickle wench was just lulling me into a false sense of security while she reached for a rock. - The Icarus Hunt by Timothy Zahn