Jump to content

Trying to run command in script but failing


Recommended Posts

Hi, I am new to automate scripting and i am trying to excite the following command

copy "c:\windows\temp\documents\custom office templates\*.*" "%userprofile%\appdata\Roaming\Microsoft\Templates\Custom.dotx"

But its failing on %userprofile%,  i just want the script to copy the file from temp to the current users path

image.thumb.png.4969a1b57a75dc22cad971d3ff0427d2.png

Is there a different command i should be using?

Link to post
Share on other sites

Yep, you have a couple issues here. 

  • First you shouldn't use the 'Shell as Admin' there's a few posts on here which will discuss why you don't use this step
  • Second you are using a Windows system variable which doesn't work with Automate command because it's not running as the user itself

You have 1 of 2 ways to accomplish this.

  • Simple way though not exactly all that reliable, you can set the 'If' to 'Console Logged On'. Obviously this will only run if the user is logged in, you would then use the 'Console Shell' function. If the user doesn't have access to the temp folder then it wouldn't work
  • The other way would be to
    • precede this with a Script Step with
      • Function: Variable Set
      • Set Type: Sql Query
      • parameter: SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(LastUsername,'\\',-1) ,',',1) FROM Computers WHERE computerID = "%computerID"
      • Variable Name: LastUser
    • change the Script Step you have here to
      • Function: shell
      • Source Patch: copy "c:\win..." "c:\@LastUser@\... 

 

The @@ uses the variable created with the Variable Set function

This is just a simple option, obviously if there home folder is different from their user name it wouldn't work.  I'm sure someone else has a more eloquent method than I do but figure at least give you a start

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...