Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 02-10-2007, 11:37 AM   #1 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default Windows Actions

how do I use windows actions in C#? Is there is a class for this?
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-10-2007, 11:46 AM   #2 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

What do you mean by Windows actions?
mordero is offline   Reply With Quote
Old 02-12-2007, 12:23 PM   #3 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

windows actions as in... uhh. like Reboot? Uhm, eject disk? Power-Off. Create account. etc.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-12-2007, 12:45 PM   #4 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

You might be able to use the System.Management namespace for some of that (just found that on a quick google search) but you can also do all of that using PInvoke and the Window APIs. Just search google for code on how to do some of that stuff...

A useful website if you start using the APIs
pinvoke.net: the interop wiki!
mordero is offline   Reply With Quote
Old 02-12-2007, 12:47 PM   #5 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Quote:
Originally Posted by Storm33229 View Post
windows actions as in... uhh. like Reboot? Uhm, eject disk? Power-Off. Create account. etc.
I highly doubt thats as simply as your hoping it is. And pinvoke.net is a godsend
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-12-2007, 12:48 PM   #6 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

well it's probably not as simple as creating a new instance of an account and defining specific variables belonging to it... but it has got to be possible to do it somehow. and I am figuring C# has a class to do it, just do not know how.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-12-2007, 01:19 PM   #7 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

Like I said, check out the System.Managment namespace and see if it has anything to offer you. And you can do these things using the Windows APIs, it just takes some work...
mordero is offline   Reply With Quote
Old 02-12-2007, 01:21 PM   #8 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by mordero View Post
Like I said, check out the System.Managment namespace and see if it has anything to offer you. And you can do these things using the Windows APIs, it just takes some work...
aight cool. I'll check it out when i get home. (@school)
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-12-2007, 01:24 PM   #9 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Quote:
Originally Posted by mordero View Post
Like I said, check out the System.Managment namespace and see if it has anything to offer you. And you can do these things using the Windows APIs, it just takes some work...
System.Management is more for info, Ive not found much in the way of doing things with it, its more for info about the PC. Its also a big pain in the ass to use
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-12-2007, 01:27 PM   #10 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

Lol ok, so dont use System.Management haha

(I didnt even know about it until I searched for restarting a comp in c# on google)
mordero is offline   Reply With Quote
Old 02-12-2007, 01:34 PM   #11 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Applications and services can query for interesting management information (such as how much free space is left on the disk, what is the current CPU utilization, which database a certain application is connected to, and much more), using classes derived from ManagementObjectSearcher and ManagementQuery, or subscribe to a variety of management events using the ManagementEventWatcher class. The accessible data can be from both managed and unmanaged components in the distributed environment.

System.Management Namespace
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-12-2007, 02:05 PM   #12 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Jeff View Post
Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. Applications and services can query for interesting management information (such as how much free space is left on the disk, what is the current CPU utilization, which database a certain application is connected to, and much more), using classes derived from ManagementObjectSearcher and ManagementQuery, or subscribe to a variety of management events using the ManagementEventWatcher class. The accessible data can be from both managed and unmanaged components in the distributed environment.

System.Management Namespace
So you're saying I could write a simple console program using that namespace that will allow me to output all the property values of my computer? # of accounts, account names + passwords etc etc etc.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-12-2007, 02:07 PM   #13 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

maybe the account names (I havent looked at the link yet cause im trying to study for an exam), but not the passwords, I belive they are encrypted (or hashed) even if this namespace provided access to them, which i doubt.

Last edited by mordero; 02-12-2007 at 02:19 PM.
mordero is offline   Reply With Quote
Old 02-12-2007, 02:26 PM   #14 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by mordero View Post
maybe the account names (I havent looked at the link yet cause im trying to study for an exam), but not the passwords, I belive they are encrypted (or hashed) even if this namespace provided access to them, which i doubt.
Ah, well, I basically want to write a password recovery program for my computer just incase anything ever happens.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-12-2007, 02:39 PM   #15 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

Hmmm, well google is your friend.

Also, Im now pretty sure the passwords are encrypted, not hashed because there are programs out there that will crack them for you (although if they use brute force, then they could be hashed).
mordero is offline   Reply With Quote
Old 02-12-2007, 03:03 PM   #16 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Quote:
Originally Posted by Storm33229 View Post
So you're saying I could write a simple console program using that namespace that will allow me to output all the property values of my computer? # of accounts, account names + passwords etc etc etc.
You can essential see and get any info from this WMI API
WMI Reference
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-13-2007, 12:51 PM   #17 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,186
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Jeff View Post
You can essential see and get any info from this WMI API
WMI Reference
Seems like you can't use C# with Windows API's. =/ But that was just my observation. Enlighten me plz.
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 02-13-2007, 01:57 PM   #18 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Quote:
Originally Posted by Storm33229 View Post
Seems like you can't use C# with Windows API's. =/ But that was just my observation. Enlighten me plz.
Bull look for System.Management stuff, you use it like a database. Ill look for old code.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-13-2007, 02:17 PM   #19 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

Quote:
Originally Posted by Storm33229 View Post
Seems like you can't use C# with Windows API's. =/ But that was just my observation. Enlighten me plz.
First result on google:
C# And API's

You can find almost anything if you just search for it.

and pinvoke.net: the interop wiki! will help with that...
mordero is offline   Reply With Quote
Old 02-13-2007, 03:02 PM   #20 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

Example of how I used that namespace, before FileSystem.GetDrives() worked . Not to mention the amount of info u can get out of these objects.

Code:
 foreach( ManagementObject wmi_HD in searcher.Get() )
            {
                Drive d = new Drive( wmi_HD );
                 m_Drivetable.Add( d.Model, d );
            }
Then in Drive i did this

Code:
public Drive( ManagementObject hdd)
        {
            m_BytesPerSector = ( uint )hdd["BytesPerSector"] ;
            m_DeviceID = ( string )hdd["DeviceID"] ;
            m_Index = ( uint )hdd["Index"] ;
            m_InterfaceType = ( string )hdd["InterfaceType"] ;
            m_Manufacturer = ( string )hdd["Manufacturer"] ;
            m_MediaType = ( string )hdd["MediaType"] ;
            m_Model = ( string )hdd["Model"] ;
            m_Name = ( string )hdd["Name"] ;   
            m_Partitions = ( uint )hdd["Partitions"] ;
            m_SectorsPerTrack = ( uint )hdd["SectorsPerTrack"] ;
            m_Signature = ( uint )hdd["Signature"] ;
            m_Size = ( ulong )hdd["Size"] ;
            m_Status = ( string )hdd["Status"];
            m_TotalCylinders = ( ulong )hdd["TotalCylinders"];
            m_TotalHeads = ( uint )hdd["TotalHeads"];
            m_MaxSectors = ( ulong )hdd["TotalSectors"];
            m_TotalTracks = ( ulong )hdd["TotalTracks"];
        }
Hope this helps, but like i said, this stuff is mostely for Info.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-13-2007, 05:17 PM   #21 (permalink)
Forum Expert
 
Kenny164's Avatar
 
Join Date: Sep 2004
Location: Ballymena, Northern Ireland
Age: 23
Posts: 464
Send a message via MSN to Kenny164
Default

If you want do simple stuff like reboot the computer, Why don't you just get C# to run a BAT file? That would be the simple way...

Although, you won't be able to find any info about the computer (e.g. drives) unless you crack into the WMI as Jeff and Mordero says.
__________________
Use the middle mouse button on Here for forum rules, if nothing happens get firefox and try again!!!
Kenny164 is offline   Reply With Quote
Old 02-13-2007, 08:59 PM   #22 (permalink)
ConnectUO Creator
 
Jeff's Avatar
 
Join Date: Jan 2004
Age: 28
Posts: 4,886
Default

pinvoke.net: WTSShutdownSystem (wtsapi32)
pinvoke.net: CM_Request_Device_Eject (setupapi)
pinvoke.net: InitiateSystemShutdown (advapi32)
pinvoke.net: CredWrite (advapi32)

Just a few all on that page tho.
__________________
Jeff Boulanger
ConnectUO - Core Developer

Want to help make ConnectUO better? Click here to submit your ideas/requests
Use your talent to compete against other community members in RunUO hosted coding competitions

If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team.


Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO
Jeff is offline   Reply With Quote
Old 02-13-2007, 09:09 PM   #23 (permalink)
Forum Expert
 
mordero's Avatar
 
Join Date: Nov 2003
Location: Illinois, USA
Age: 22
Posts: 2,911
Default

*loves pinvoke.net*

*loves google*
mordero is offline   Reply With Quote