Console commands of Windows 7 (TCP/IP connection)
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Console commands of Windows 7 (TCP/IP connection)
Hello
Help please, alternative to the console commands Windows 7(how to get the results of these commands on PB with winapi or in some other way):
1) net session
2) net session [computer name] / delete
3) openfiles /query /fo CSV /nh /v
4) openfiles /disconnect /id X
thank
upd:
may need to use NetFileEnum_ (...
but how, and in conjunction with what other functions?
Help please, alternative to the console commands Windows 7(how to get the results of these commands on PB with winapi or in some other way):
1) net session
2) net session [computer name] / delete
3) openfiles /query /fo CSV /nh /v
4) openfiles /disconnect /id X
thank
upd:
may need to use NetFileEnum_ (...
but how, and in conjunction with what other functions?
Re: Console commands of Windows 7 (TCP/IP connection)
http://msdn.microsoft.com/en-us/library ... s.85).aspx
1. list all open sessions with NetSessionEnum
2. close the session with NetSessionDel
3. list all open files with NetFileEnum
4. close the file with NetFileClose
1. list all open sessions with NetSessionEnum
2. close the session with NetSessionDel
3. list all open files with NetFileEnum
4. close the file with NetFileClose
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
Code: Select all
Structure SESSION_INFO_1
cname.l
username.l
num_opens.w
time.w
open_time.w
user_flags.w
dead_time.l
EndStructure
*Buffer.Session_info_1
Num.l
Total.l
success=NetSessionEnum_(0, 0, 0, 1, @*Buffer, -1, @Num, @Total, 0)
If success = 0 And success <> #ERROR_MORE_DATA
For i=1 To Num
Debug "Num - "+Str(Num)
Debug "Total - "+Str(Total)
Debug "cname - "+PeekS(*Buffer\cname, -1, #PB_Unicode)
Debug "username - "+PeekS(*Buffer\username , -1, #PB_Unicode)
Debug "num_opens - "+Str(*Buffer\num_opens)
Debug "time - "+Str((*Buffer\time))
Debug "open_time. - "+FormatDate("%hh:%ii:%ss",*Buffer\open_time)
Debug "user_flags - "+Str(*Buffer\user_flags)
Debug "dead_time - "+FormatDate("%hh:%ii:%ss",*Buffer\dead_time)
Debug "********************"
Next
EndIf
NetApiBufferFree_(*buffer)
help please...
PS: http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Re: Console commands of Windows 7 (TCP/IP connection)
Hi,
try this:
Addas last line inside the loop.
Bernd
try this:
Add
Code: Select all
*Buffer + SizeOf(SESSION_INFO_1)Bernd
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
HIinfratec wrote: try this:
Addas last line inside the loop.Code: Select all
*Buffer + SizeOf(SESSION_INFO_1)
Bernd
on the line:
Code: Select all
Debug "cname -" + PeekS (* Buffer \ cname, -1, # PB_Unicode)ps: http://pinvoke.net/default.aspx/netapi3 ... nEnum.html
http://forum.sources.ru/index.php?showtopic=8537
Re: Console commands of Windows 7 (TCP/IP connection)
Hi,
I think your structure is complete wrong.
It should be:This results in:Please try it, since I have no open sessions
Bernd
I think your structure is complete wrong.
It should be:
Code: Select all
typedef struct _SESSION_INFO_1 {
LPWSTR sesi1_cname;
LPWSTR sesi1_username;
DWORD sesi1_num_opens;
DWORD sesi1_time;
DWORD sesi1_idle_time;
DWORD sesi1_user_flags;
} SESSION_INFO_1, *PSESSION_INFO_1, *LPSESSION_INFO_1;Code: Select all
Structure _SESSION_INFO_1
sesi1_cname.i
sesi1_username.i
sesi1_num_opens.l
sesi1_time.l
sesi1_idle_time.l
sesi1_user_flags.l
EndStructure
*Buffer._SESSION_INFO_1 = #Null
Define Num.l
Define Total.l
success = NetSessionEnum_(#Null, #Null, #Null, 1, @*Buffer, -1, @Num, @Total, #Null)
If success = 0 Or success = #ERROR_MORE_DATA
Debug "Num - " + Str(Num)
Debug "Total - " + Str(Total)
Debug "---------------------------"
*Ptr._SESSION_INFO_1 = *Buffer
For i = 1 To Num
Debug "cname - " + PeekS(*Ptr\sesi1_cname, -1, #PB_Unicode)
Debug "username - " + PeekS(*Ptr\sesi1_username , -1, #PB_Unicode)
Debug "num_opens - " + Str(*Ptr\sesi1_num_opens)
Debug "time - " + Str((*Ptr\sesi1_time))
Debug "idle_time. - " + FormatDate("%hh:%ii:%ss",*Ptr\sesi1_idle_time)
Debug "user_flags - " + Str(*Ptr\sesi1_user_flags)
Debug "********************"
*Ptr + SizeOf(_SESSION_INFO_1)
Next
EndIf
If *Buffer : NetApiBufferFree_(*Buffer) : EndIfBernd
Re: Console commands of Windows 7 (TCP/IP connection)
Hi,
I had to modify the code above
I used .l for the pointers.
Since you want to use it in 64bit I had to change it to .i (which is always better for pointers)
Thanks Danilo for the hint
Bernd
I had to modify the code above
I used .l for the pointers.
Since you want to use it in 64bit I had to change it to .i (which is always better for pointers)
Thanks Danilo for the hint
Bernd
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
Hi.
Thank you very much!!
Final version of the:
the result:
Thank you very much!!
Final version of the:
Code: Select all
Structure _SESSION_INFO_2
sesi2_cname.i
sesi2_username.i
sesi2_num_opens.l
sesi2_time.l
sesi2_idle_time.l
sesi2_user_flags.l
sesi2_cltype_name.i
EndStructure
*Buffer._SESSION_INFO_2 = #Null
Num.l
Total.l
success=NetSessionEnum_(#Null, #Null, #Null, 2, @*Buffer, -1, @Num, @Total, #Null)
If success = 0 And success <> #ERROR_MORE_DATA
Debug "Num - "+Str(Num)
Debug "Total - "+Str(Total)
Debug "---------------------------"
*Ptr._SESSION_INFO_2 = *Buffer
For i=1 To Num
Debug "cname - "+PeekS(*Ptr\sesi2_cname, -1, #PB_Unicode)
Debug "username - "+PeekS(*Ptr\sesi2_username , -1, #PB_Unicode)
Debug "num_opens - "+Str(*Ptr\sesi2_num_opens)
Debug "time - "+ FormatDate("%dd", *Ptr\sesi2_time-(60*60*24) ) + " day / " + FormatDate("%hh:%ii:%ss", *Ptr\sesi2_time)
Debug "idle_time - "+ FormatDate("%dd", *Ptr\sesi2_idle_time-(60*60*24) ) + " day / " + FormatDate("%hh:%ii:%ss", *Ptr\sesi2_idle_time)
Debug "user_flags - "+Str(*Ptr\sesi2_user_flags)
Debug "cltype_name - "+Str(*Ptr\sesi2_cltype_name)
Debug "********************"
*Ptr + SizeOf(_SESSION_INFO_2)
Next
EndIf
If *Buffer : NetApiBufferFree_(*Buffer) : EndIfNum - 8
Total - 8
---------------------------
cname - 172.28.42.44
username - AAAAAAAAA
num_opens - 5
time - 00 day / 05:02:07
idle_time - 00 day / 00:00:28
user_flags - 0
cltype_name - 6474144
********************
cname - 172.28.42.84
username - BBBBBBBBB
num_opens - 2
time - 00 day / 04:59:32
idle_time - 00 day / 01:27:23
user_flags - 0
cltype_name - 6474620
********************
cname - 172.28.42.52
username - CCCCCCCCC
num_opens - 1
time - 00 day / 04:18:57
idle_time - 00 day / 00:09:41
user_flags - 0
cltype_name - 6474852
********************
cname - 172.28.42.71
username - DDDDDDDDD
num_opens - 1
time - 00 day / 04:49:50
idle_time - 00 day / 01:46:48
user_flags - 0
cltype_name - 6473668
********************
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
What is missing?:
an error 87
a:
an error 53
PS: http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Code: Select all
Debug NetSessionDel_ (# Null, # Null, # Null)a:
Code: Select all
Procedure.s GetComputerName ()
buffer.s = Space (64)
bufsize.l = 64
GetComputerName_ (@ buffer, @ bufsize)
ProcedureReturn buffer
EndProcedure
Debug NetSessionDel_ ("\ \ \ \" + GetComputerName (), "\ \ \ \ 172.28.42.44", # Null)PS: http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Last edited by registrymechanic22 on Mon Jan 30, 2012 1:02 pm, edited 1 time in total.
Re: Console commands of Windows 7 (TCP/IP connection)
You're welcomeregistrymechanic22 wrote:Hi.
Thank you very much!!![]()
Btw.: This makes no sense:
Code: Select all
If success = 0 And success <> #ERROR_MORE_DATABernd
Re: Console commands of Windows 7 (TCP/IP connection)
It is not allowed to have all parameters #Nullregistrymechanic22 wrote:What is missing?:Code: Select all
Debug NetSessionDel_ (#Null, #Null, #Null)
The second or third parameter has to be a valid entry:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Code: Select all
Debug NetSessionDel_ ("\ \ \ \" + GetComputerName (), "\ \ \ \ 172.28.42.44", #Null)Test:
Code: Select all
Debug NetSessionDel_ ("\\" + GetComputerName (), "\\172.28.42.44", #Null)Code: Select all
Debug NetSessionDel_ (@"\\" + GetComputerName (), @"\\172.28.42.44", #Null)P.S.: Sorry, but I can not test this stuff.
I'm logged in a domain, but I have no sessions
-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
ok, thank you.infratec wrote: This makes no sense:
Bernd
Code: Select all
Procedure.s GetComputerName()
buffer.s=Space(64)
bufsize.l=64
GetComputerName_(@buffer, @bufsize)
ProcedureReturn buffer
EndProcedure
Debug NetSessionDel_(#Null, "\\172.28.42.44", #Null)Code: Select all
Procedure.s GetComputerName()
buffer.s=Space(64)
bufsize.l=64
GetComputerName_(@buffer, @bufsize)
ProcedureReturn buffer
EndProcedure
Debug NetSessionDel_("\\"+GetComputerName(), "\\172.28.42.44", #Null)
Re: Console commands of Windows 7 (TCP/IP connection)
Hi,
Try the '@' infront of the strings (see my last post above),
because you need aBernd
Try the '@' infront of the strings (see my last post above),
because you need a
Better would bepointer to a string
Code: Select all
Help$ = "\\172.28.42.44"
(#Null, @Help$, ...Re: Console commands of Windows 7 (TCP/IP connection)
Code: Select all
#ERROR_ACCESS_DENIED = 5
#ERROR_BAD_NETPATH = 53
#ERROR_INVALID_PARAMETER = 87
#NERR_ClientNameNotFound = 2312
#NERR_InvalidComputer = 2351
#NERR_NoSuchServer = 2460
#NERR_NoSuchSession = 2461-
registrymechanic22
- Enthusiast

- Posts: 176
- Joined: Sun Jun 28, 2009 7:07 pm
- Location: RUS
Re: Console commands of Windows 7 (TCP/IP connection)
Code: Select all
Procedure.s GetComputerName()
buffer.s=Space(64)
bufsize.l=64
GetComputerName_(@buffer, @bufsize)
ProcedureReturn buffer
EndProcedure
Servername.s = "\\"+GetComputerName()
UncClientName.s = "\\172.28.42.44""
Debug NetSessionDel_(@Servername, #Null, #Null)
Debug NetSessionDel_(#Null, @UncClientName, #Null)
Debug NetSessionDel_(@Servername, @UncClientName, #Null)53
2312 ; 172.28.42.44 - taken from NetSessionEnum_(
53
