0

This question already has an answer here:

I have a written a script (in R)

cmd = paste0("schtasks /create /sc WEEKLY /d MON /tn ",task," /tr ",comm," /st 12:51")
system(command = cmd)

Where task is the name of the task and comm is the location of R and the script. This works and the script is executed. However I have some scripts where I would like to pass my credentials.

Essentially this is just adding /RU *** /RP *** to cmd, however I don't think storing my username and password is a good idea in a shared file.

Is there a way to encrypt the credentials or maybe another alternative?

marked as duplicate by M'vy, Xiong Chiamiov, forest, schroeder Feb 1 '18 at 10:07

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Probably better suited for StackOverflow. – Tom K. Jan 31 '18 at 15:51
  • Do you need elevated permissions to run the task on the system, or do you need to access another system? – Shane Andrie Jan 31 '18 at 15:52
1

Rather than doing it in R, you can do it in Powershell and save the credentials as a secure string. That solves the problem of it being human-readable, but the credentials used to create it are still available (which is not a good security practice). More info on that is available here. Otherwise you can do this in Powershell and use get-credential, which prompts you to enter the appropriate credentials. (That's a lot more secure way to handle that, although it comes with the "bother" of entering your ID and password)

  • The credentials would still be in the script and Secure-String is only used to prevent attacks against strings in memory. A schedule task is not going to work with get-credential due to the prompt – McMatty Jan 31 '18 at 20:46
  • This might be a simple (read: not ideal) suggestion, but you could use an algorithm to encrypt these fields and store these encrypted fields in, say, a locked file, in a way that is also not human readable. Then, implement a way to decrypt this input into the script and read the input from the stored location into a variable you can then use and discard from memory after. This might allow you to automate the process but likewise, this isn't 100% secure. – psosuna Feb 1 '18 at 0:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.