Variable name in cmd string

Hi all,

First time on this forum. But it helped me out many times. Thank you all for that!
I have a question were I can’t seem to find an answer on.

For an automation project I am starting to run cmd.exe as a different user (shift+right, normally).
For that, I use a predefined string. For security reasons I would like to retrieve credentials from orchestrator. That part is working fine, since entering password as secure string is working great.
The string I want to use is:
"runas /netonly /user:domain\" + RobotUsername.ToString + Chr(34) +"mmc %windir%\system32\dsa.msc"+ Chr(34)

That one is throwing an error at the start of the sequence with: reference not set to an object.

When I use the following without a variable:
"runas /netonly /user:domain\RobotUsername" + Chr(34) +"mmc %windir%\system32\dsa.msc"+ Chr(34)

Everything is working great. I found out that the variable is not empty.
The string runs when I remove the “To.String” part, but obviously it’s empty then.

Does anybody bump into this before and can help me further?

Thank you so much in advance.
Mapi.

Hi @martijn.pirozzi,

First of all, welcome UiPath Forum :slight_smile:

Are you sure about the variable is not empty? Because toString does not causes this error.

Can you share screenshot of the error and variable’s value?

Regards.
Ömer

Hi Omer,

Error:
image

Check resulting in not empty:

Really only when I add To.String it´s causing this.

Thanks for responding.

So, it is really breaking on the start sequence already:
image

Hi @martijn.pirozzi ,

Could you confirm again on the variables used for the Get Credential Activity and also try using a Write Line or Log Message Activity with .ToString suffixed and Check whether it gives out an Error.

Maybe also check in the Debug Panel what is the value of RobotUsername variable.

Here, we can see RobotUsername name is used as a variable

Here, the variable name is used as a literal and not the value of the variable RobotUsername

Let us know your findings after a Debug and check using Immediate Panel.

Hello @martijn.pirozzi

Here as per the screenshot RobotCredentials is the Asset name and can you confirm RobotUsername is the variable used inside the username field in Get credential activity??

Also plz cross check d credentials created in orchestrator.

Thanks

@martijn.pirozzi,

Actually you don’t need to use .ToString. Because the username is string.

If username is empty, maybe you don’t get error when writing the username. But it will write blank value.

Please check you credential’s username from orchestrator or use log message to print your username to output.

Regards.
Ömer

Thanks all for responding.

Of course I tried to log the username as a debug method. It logs it perfectly, but it just doesn’t print it in the string of cmd. So

  1. it’s not printing the username in the cmd command, but in the log message it does
  2. adding To.String caused the flow not to run at all.

This rules out that orchestrator credentials are not right or any of these things. The variable is 100% coming in to the workflow and is saved in the variable which RobotUsername which is indeed used in the GetCredential activity.

Hi @martijn.pirozzi
What happens when you use this?
"runas /netonly /user:domain\“ + RobotUsername + Chr(34) +“mmc %windir%\system32\dsa.msc”+ Chr(34)

Hi Emira,
As mentioned before that’s resulting in an empty place where the username should be. I tried literally everything.

Ok. So the problem is not the .Tostring as you’re having a blank value even without it.

Can you try this:

String.Format("runas /netonly /user:domain\{0}"  + Chr(34) +"mmc %windir%\system32\dsa.msc"+ Chr(34), RobotUsername)

@martijn.pirozzi
If that does not work, the only possible explanation to this, is that you have two variables named RobotUserName but in different scopes, and the one you’re using in your command line is empty. Please recheck the variables and their scopes and make sure the value is correctly passed in the right flow.

1 Like

Good thinking! I have no idea why I haven’t thought of this one.

I’ll try it Monday morning. Work laptop stays closed for the weekend. Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.