rossy Posted July 21, 2018 Share Posted July 21, 2018 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? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 21, 2018 Share Posted July 21, 2018 (edited) Check for the @error code after the calling of the function. Edited July 21, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
rossy Posted July 21, 2018 Author Share Posted July 21, 2018 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? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 21, 2018 Share Posted July 21, 2018 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: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
rossy Posted July 21, 2018 Author Share Posted July 21, 2018 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. Link to comment Share on other sites More sharing options...
Earthshine Posted July 21, 2018 Share Posted July 21, 2018 press F1 in the editor My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
rossy Posted July 21, 2018 Author Share Posted July 21, 2018 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. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 21, 2018 Share Posted July 21, 2018 (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 July 22, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
rossy Posted July 22, 2018 Author Share Posted July 22, 2018 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? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 22, 2018 Share Posted July 22, 2018 So, $strRetVal is blank? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
rossy Posted August 6, 2018 Author Share Posted August 6, 2018 On 22/07/2018 at 6:55 AM, FrancescoDiMuro said: So, $strRetVal is blank? The value returned is "0" Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted August 7, 2018 Share Posted August 7, 2018 @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: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
DonChunior Posted August 7, 2018 Share Posted August 7, 2018 @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! Link to comment Share on other sites More sharing options...
rossy Posted August 17, 2018 Author Share Posted August 17, 2018 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 FrancescoDiMuro 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now