Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# Over the network

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 16, 2011 3:50 pm    Post subject: C# Over the network Reply with quote

This is for Wiccaan in particular, if anyone knows it's probably him.

In C# is there a way to get the current logged in user of a remote computer. I know it can be done in VB and we already have a script for that. I am looking to make one in C# to add to a code project I did today, well not really a code project.

It takes a text file parses out the IP list to a listBox, I want to add a column to query for the current user of that system.

It's to be used in conjunction with NMAP. This would save me about 5 minutes of work not having to hit my VB script for each IP.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Wed Mar 16, 2011 4:25 pm    Post subject: This post has 1 review(s) Reply with quote

I'm guessing you mean this script:
Code:
strComputer = "atl-ws-o1"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
 
For Each objComputer in colComputer
    Wscript.Echo "Logged-on user: " & objComputer.UserName
Next


Not really familiar with WMI in C# but after some digging and tinkering I came up with this, works on my computer so I guess it should be ok:

Code:

        public string[] GetLoggedUsers(string strCompName)
        {
            try
            {
                // Create connection.
                ManagementScope mScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", strCompName));
                mScope.Options.EnablePrivileges = true;
                mScope.Connect();

                // Failed to connect?
                if (mScope.IsConnected == false)
                    throw new Exception("Unable to connect to remote host.");

                // Create query to system information.
                SelectQuery sql = new SelectQuery("select * from Win32_ComputerSystem");

                // Obtain object collection.
                ManagementObjectSearcher mos = new ManagementObjectSearcher(mScope, sql);

                var vUsers = from ManagementObject mo in mos.Get()
                             select mo["UserName"];

                return vUsers.Cast<string>().ToArray();
            }
            catch
            {
                return default(string[]);
            }
        }


Example:
Code:

string[] strTest = GetLoggedUsers("atom0s-win7");


You need to use:
using System.Management;

And be sure to add the reference to your project for it as well.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed Mar 16, 2011 8:37 pm    Post subject: Reply with quote

I tried something similar but it kept replying with my username not the remotes. We don't have the one from MS, our in house programmer ripped one out for me. Dropped it in system32 so usage is from command prompt, curUser <IP>

returns messagebox with IP, domain\user

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Thu Mar 17, 2011 12:45 am    Post subject: Reply with quote

AhMunRa wrote:
I tried something similar but it kept replying with my username not the remotes. We don't have the one from MS, our in house programmer ripped one out for me. Dropped it in system32 so usage is from command prompt, curUser <IP>

returns messagebox with IP, domain\user


Is it a program or a script? Mine pm'ing it to me. I'll see if I can toss together a C# version of it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Mar 17, 2011 9:14 pm    Post subject: Reply with quote

Yeah, will get it tomorrow. Have been slammed at the office we lost another person in our department, so work load has doubled. Been doing 12 hour days without lunch.

He wrote a script in VB6.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Mar 21, 2011 8:26 am    Post subject: Reply with quote

Sorry took me so long, but was super busy all weekend. Here is his code.

Code:
On Error Resume Next
dim WshShell,oArgs,FSO

set oArgs = wscript.Arguments

if InStr(oArgs(0), "?") <> 0 then
   wscript.echo VBCRLF & "? HELP ?" & VBCRLF
   Usage
end if

if oArgs.Count < 1 then
   wscript.echo VBCRLF & "! Usage Error !" & VBCRLF
   Usage
end if

strComputer = oArgs(0)

Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")
WinPath = WshEnv("SystemRoot")&"\System32\wscript.exe"
Set FSO = CreateObject("Scripting.FileSystemObject")

if FSO.FileExists(winpath) then
'wscript.echo winpath & " " & "verified"
else
wscript.echo "!! ERROR !!" & VBCRLF & "Can't find of verify " & winpath & "." & VBCRLF & "You must be running Windows 2000 better for this script to work."
Set WshShell = Nothing
Set WshEnv = Nothing
Set oArgs = Nothin
Set FSO = Nothing
wscript.quit
end if

'wscript.echo "--HERE--"
'rc = WshShell.Run("wscript " & "curUser.vbs " & strComputer & CHR(34), 2, FALSE)
'Wscript.Sleep 60 'wait for window to open.
'WshShell.AppActivate(WinPath)

Set WshShell = Nothing
Set oArgs = Nothing
Set WshEnv = Nothing
Set FSO = Nothing

Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputer = objWMIService.ExecQuery _
   ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
   Wscript.Echo "Computer IP: " & strComputer & VBCRLF & "Logged-on user: " & objComputer.UserName
Next
wscript.quit

Sub Usage()
On Error Resume Next
msg = "Usage: cscript|wscript currentUser.vbs IP" & VBCRLF & VBCRLF & "You should include the ip." & VBCRLF & VBCRLF & "For example:" & VBCRLF & VBCRLF &

"cscript currentUser.vbs 192.168.1.1" & VBCRLF & VBCRLF & "cscript currentUser.vbs /?|-? will display this message."

wscript.echo msg

wscript.quit

end sub
[/code]
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Mon Mar 21, 2011 1:39 pm    Post subject: Reply with quote

The above code I gave does this same script effect. It wont work on systems that don't have given services activated though to allow network queries. (I forget which service it is, but it has to be enabled to query things like users and so on.)

I just tested my version again with both my local IP as well as my systems name and it worked fine for me. (Windows 7) I can't query my XP laptop since I disabled the service it used a while back and don't remember which it is to re-enable it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Mon Mar 21, 2011 2:19 pm    Post subject: Reply with quote

Tried your code and also another piece of code that is similar. I've gotten farther with yours, the other code failed on .Get(). Not sure why.

Yours is returning an empty string[] object. I have added an error check to the catch to make sure that I'm not seeing the default string[] null and that error is not popping. It still isn't returning anything and this is from my local machine.

EDIT*** ignore this post. It works perfect. I was calling

string[] user = GetLoggedUsers(IPbox.Text);
MessageBox.Show(user.ToString());

changed to MessageBox.Show(user[0].ToString());

Works great. Thank you Wiccaan.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Mon Mar 21, 2011 2:24 pm    Post subject: Reply with quote

AhMunRa wrote:

EDIT*** ignore this post. It works perfect. I was calling

string[] user = GetLoggedUsers(IPbox.Text);
MessageBox.Show(user.ToString());

changed to MessageBox.Show(user[0].ToString());

Works great. Thank you Wiccaan.


No problem and yeah, the return is an array of strings since more then one user can be found. Glad it works. Smile

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Mar 21, 2011 3:29 pm    Post subject: Reply with quote

Wiccaan wrote:
I'm guessing you mean this script:
Code:
strComputer = "atl-ws-o1"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
 
For Each objComputer in colComputer
    Wscript.Echo "Logged-on user: " & objComputer.UserName
Next


Not really familiar with WMI in C# but after some digging and tinkering I came up with this, works on my computer so I guess it should be ok:

Code:

        public string[] GetLoggedUsers(string strCompName)
        {
            try
            {
                // Create connection.
                ManagementScope mScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", strCompName));
                mScope.Options.EnablePrivileges = true;
                mScope.Connect();

                // Failed to connect?
                if (mScope.IsConnected == false)
                    throw new Exception("Unable to connect to remote host.");

                // Create query to system information.
                SelectQuery sql = new SelectQuery("select * from Win32_ComputerSystem");

                // Obtain object collection.
                ManagementObjectSearcher mos = new ManagementObjectSearcher(mScope, sql);

                var vUsers = from ManagementObject mo in mos.Get()
                             select mo["UserName"];

                return vUsers.Cast<string>().ToArray();
            }
            catch
            {
                return default(string[]);
            }
        }


Example:
Code:

string[] strTest = GetLoggedUsers("atom0s-win7");


You need to use:
using System.Management;

And be sure to add the reference to your project for it as well.


Wiccan just ported this VB source, give credits next time you fucking dick sucker.

Code:
http://www.tek-tips.com/viewthread.cfm?qid=1017596&page=409


Google makes you a 1337 hacker, Smile
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Mon Mar 21, 2011 10:46 pm    Post subject: This post has 1 review(s) Reply with quote

I didn't take credit for the script nub, I simply said 'do you mean this?'. I never once stated 'I wrote this'. Seriously please go play in traffic and do the world a favor.

And no you are wrong, I converted this one:
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/desktop/logon/

Which in turn is used elsewhere. Which again I never took credit for.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Mar 22, 2011 1:38 am    Post subject: Reply with quote

Wiccaan wrote:
I didn't take credit for the script nub, I simply said 'do you mean this?'. I never once stated 'I wrote this'. Seriously please go play in traffic and do the world a favor.

And no you are wrong, I converted this one:
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/desktop/logon/

Which in turn is used elsewhere. Which again I never took credit for.


you seriously want me banned to keep making noobs think you're a godly programmer, do you ? Smile

you're just another idiot who use google for code, you were never special with your useless shit, you just made a lame trainer with fancey GUI for Tony Hawk and stickied it to make people you're god, hahahaha.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8585
Location: 127.0.0.1

PostPosted: Tue Mar 22, 2011 6:20 am    Post subject: Reply with quote

Gabe Newell wrote:
Wiccaan wrote:
I didn't take credit for the script nub, I simply said 'do you mean this?'. I never once stated 'I wrote this'. Seriously please go play in traffic and do the world a favor.

And no you are wrong, I converted this one:
http://www.activexperts.com/activmonitor/windowsmanagement/scripts/desktop/logon/

Which in turn is used elsewhere. Which again I never took credit for.


you seriously want me banned to keep making noobs think you're a godly programmer, do you ? Smile

you're just another idiot who use google for code, you were never special with your useless shit, you just made a lame trainer with fancey GUI for Tony Hawk and stickied it to make people you're god, hahahaha.


The funny part is you are the one whom keeps bringing up the fact that I'm some programming god. I have never once referenced myself as being better then anyone on this forum. I never belittle anyone whom is learning or may do something wrong, I offer suggestions, give my personal opinions and experiences, and share what I know.

I think you are personally upset with me due to your terrible reputation because every time you posted code I could easily prove you ripped it. Rip by the fact is due to you taking credit for others code. Something I have never done. Go around the net and look at any of my public projects, all of them contain credits lists because I respect the work and help of others.

The reason I have a problem with you is because of things like this. You speak out of context, with little knowledge of what you are attempting to accuse me of (let alone the fact that all you did was rip when you posted code here) and then try to belittle me in the process. Firstly, sorry but I'm sure everyone here can form their own opinion about me whether it be good or not. It's an opinion, they are entitled to it. Secondly, I could care less if they don't like me. I don't do anything to cause someone to flip shit on me like a child. (Like what you are doing now.)

It's bee what? 5 or so years now I'm sure you are around 18ish now, why not grow up and move on? Start acting your age, it will help you in life.

Edit : On a side note as well, I didn't sticky the trainer topic I posted, Snowfox did. If you actually looked at the thread when you originally posted in it years ago rather then looked for some reason to look cool, you would have seen that already. It would also help if I was even a moderator of that section, which I'm not.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Tue Mar 22, 2011 10:04 am    Post subject: Reply with quote

Doesn't matter where the solution came from, whether it was a port of existing code or not, point is it was a working solution to my issue and the help was appreciated.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites