Jump to content

Recommended Posts

Posted

I'm trying to make a script to check whether a user has an open session on a file server. I've tried the following code:

#include <NetShare.au3>
#include <Array.au3>
$shares = _Net_Share_SessionEnum("SERVERHERE", "", "USERNAMEHERE")
_ArrayDisplay($shares)

Which always returns nothing, but when I check the Sessions on the Shared Folders SnapIn the user is connected. The account running the script is a member of the Administrators group. Any ideas?

Posted
1 hour ago, FrancescoDiMuro said:

Check for the @error code after the calling of the function.

Hi, I added the following code to the script:

If @error Then
   consolewrite("Error detected")
EndIf

And it returns as an error, is there any way of finding out more details of the error?

Posted

Sure it is :)

Since @error it is THE error code, you can add it to the ConsoleWrite() function, just like this:

; Calling the function
If @error Then
    ConsoleWrite("Error detected! Error: " & @error & @CRLF)
EndIf

You can find more about @error code in the Help file, about the function which throws the error.

Just look in the Help file about _Net_ShareSessionEnum() function, and, basing on the @error code returned, you get the cause that generates it :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

Thanks for your help @FrancescoDiMuro, this might be a stupid question but where is the help file?

I've been using this page to help me, but all there is for failure is "Failure:    sets the @error flag to non-zero."

I added your above code into my script and I got the number "10" back as the error. 

Posted
1 hour ago, Earthshine said:

press F1 in the editor

Thanks, but that gives the exact same page as I last posted and doesn't give me any further information about the error. 

Posted (edited)

This is the Help page about _Net_Share_SessionEnum.

In that page, there are no errors listed, but, as you can see from the MSDN page, you could check the return value of the function.

Just put 

Global $strRetVal = _Net_Share_SessionName(...)
ConsoleWrite("Return Value: & $strRetVal & @CRLF)

So you can see what is the result of the function :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

Thanks, but I'm still not any further forward. My code currently looks like:

#include <NetShare.au3>
Global $intRetVal = _Net_Share_SessionEnum("SERVERNAME", "", "USERNAME")
If @error Then
   ConsoleWrite("Error: " & @error)
Else
    ConsoleWrite("Return Value:" & $intRetVal & @CRLF)
EndIf

And the return I'm getting is: "Error: 10"

Looking at the MSDN page you linked above there's no failure return value that is just numbers, they're all in text?

  • 3 weeks later...
Posted

@rossy

My falut.

If the function success, it return an array, and so, you have to display the array with _ArrayDisplay() function; else, if the functions does not success, it sets the @error to non-zero, and that is what it is, since:

On 21/7/2018 at 8:10 PM, rossy said:

I added your above code into my script and I got the number "10" back as the error.

So, there is an error in your function call :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

@rossy, I can reproduce your error code 10, when I'm using an account that has no administration rights on the server.
When I run the script with an account that has admin rights on the server, it works!

  • 2 weeks later...
Posted
On 07/08/2018 at 7:29 AM, DonChunior said:

@rossy, I can reproduce your error code 10, when I'm using an account that has no administration rights on the server.
When I run the script with an account that has admin rights on the server, it works!

Thank you so much, that's exactly what it was! When running the script, I didn't right click and run as administrator.

For anyone else who may come across this thread, my final code for this was:

#RequireAdmin
#include <NetShare.au3>
#include <Array.au3>
Global $userinshare = _Net_Share_SessionEnum("SERVERHERE", "", "USERNAMEHERE")
If IsArray($userinshare) Then
   MsgBox(-1, "", "User has active sessions on server.")
Else
   MsgBox(-1, "", "User is not connected to server.")
EndIf

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...