Net Use or alternative Java/Groovy for establishing credentials on a shared drive

Hello friends in the TR TechOverflow community! My SoapUI script will delete current credentials to a shared drive & establish new ones to ensure we're connecting to "\\
clnt-corp-e0562.int.westgroup.com\\caymanci\$" with a service account. My preferred languages to accomplish this task are Groovy & Java, but I got better search results for the "NET USE" so far. So to clarify, the following is the road I've started down, but if you've got other solutions outside of Windows shell networking, I'm happier with that. So far, **c:> net use "\\
clnt-corp-e0562.int.westgroup.com\caymanci$" /delete** (& iterations thereof) result in "The network connection could not be found. More help is available by typing NET HELPMSG 2250" in the command line. I've also attempted escaping special characters and specifying the domain, all with similar results. Once I've made this concept work, I'll throw the solution into my Groovy script. Are there any Java/Groovy/SoapUI/Networking gurus out there who'd suggest a better solution than putting this in my test suite's Setup Script / know how to fix my NET USE command here? Thank you, G

Best Answer

Answers

  • Thank you Bhavin! Your solution is *perfect.* When I first looked at it, I was like "I know this; this would only get me halfway there if it even works." But seeing that you tried the solution & it worked for you was encouraging & the non-specific error I was getting using the /delete switch happens only when I haven't explicitly NET USEd the share in the same DOS window. In other words, I was attempting to /delete the pre-existing credentials I knew I'd mapped to the share via another Windows method & that 1st /delete command always gave the error: "The network connection could not be found." On this point alone, I mistakenly assumed I wasn't specifying the shared drive name correctly. Another lesson that I shouldn't doubt myself just because Windows shell doesn't give a helpful error message or know its own connections. **Persistence pays off.** Here is the SoapUI code I'm using so far in my suite Startup script: def delCredentials = "net use \\\\
    caymanstorage.int.westgroup.com\\caymanci\$ /delete" delCredentials.execute() *//if this causes an error, it's likely bc the mapping doesn't need deletion anyway; no need to report; continue script.* def newCredentials = "net use \\\\
    caymanstorage.int.westgroup.com\\caymanci\$ /USER:ECOMQC\\[service account name] [password]" newCredentials.execute() *//explicitly connect to the drive with the service account provided.* If anyone knows another/better solution, please post it here or on the hub. Thanks again T.Overflow community!