Kaseya Community

Place file in individual users folder (XP/Vista)

  • I have a softphone program that keeps its address book info in a XML file under the individual users' profile. How can I make a script that will have Kaseya drop a new file into this particular directory and overwrite the old one? On top of that, I have a mix of XP and Vista clients - the file is in the same named folder, but the folder is a few layers down and the path to get to the user folder is different for both, of course. Any thoughts?

    I'm on Kaseya 4.8, if that matters any.

    Legacy Forum Name: Place file in individual users folder (XP/Vista),
    Legacy Posted By Username: rhollingsead
  • rhollingsead
    I have a softphone program that keeps its address book info in a XML file under the individual users' profile. How can I make a script that will have Kaseya drop a new file into this particular directory and overwrite the old one? On top of that, I have a mix of XP and Vista clients - the file is in the same named folder, but the folder is a few layers down and the path to get to the user folder is different for both, of course. Any thoughts?

    I'm on Kaseya 4.8, if that matters any.


    Write the file to %UserProfile%\DirName\SubDirName\File.xml

    Michael

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: RCS-Michael
  • Ok - I tried the %userprofile% string, and I don't think it is working. Here is my script so far. I eventually added a step for impersonating a user in case it needed access, but that didn't help either. Another thing is although it always fails in step 4, it never actually deletes the file in step 3 like it is supposed to. Any help is appreciated.

    IF
    Application is running - eyebeam.exe

    THEN
    Step 1
    Close application - eyebeam.exe

    Step 2
    Impersonate user - administrator

    Step 3
    Delete file - C:\users\%userprofile%\local\counterpath\regnow basic\default_user\contacts-resource-list.xml

    Step 4 -
    Write File - C:\users\%userprofile%\local\counterpath\regnow basic\default_user\contacts-resource-list.xml
    Source file on server: contacts-resource-list.xml

    ELSE
    Nothing here yet; after the script ran correctly i was simply going to add the file copy part of the script into this area.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rhollingsead
  • Your paths are incorrect. It should be:

    Delete file - %userprofile%\local\counterpath ...

    The way you wrote it, the path evaluates to: "c:\users\c:\users\username\local\counterpath"

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • First, thanks for this tip, Lmhansen - I'm new with the scripting stuff, can you tell? Also, thanks to Michael for the original hint.

    Ok, so my script now fully executes with no errors, but the file is still not deleted or replaced. Does %userprofile% mean that it should copy to each profile on the system? I just did a search on my system, and the file I am attempting to work with is nowhere else on my system. Thoughts?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rhollingsead
  • %userprofile% is relative to the context of the user running the command. If you want to modify something in every profile folder, you need to use a batch file to loop through them. This also means that you need to upload the file you want to write before you call the batch file, and then use the batch file to copy it to the appropriate directories.

    This command in a batch file will loop through every user profile and copy the file foo.txt to the Desktop. Swap in your paths and file name, then use Kaseya to upload this file to the client. Call the batch file with Kaseya's Execute Shell Command function.


    @echo off
    cd %userprofile%\..
    for /f %%g in ('dir /ad /b') do (copy /y c:\foo.txt %%g\desktop)


    The first line suppresses output.
    The second line changes to the root of the user profile location - for XP, this would be c:\documents and settings. For Vista, it's c:\users. You'll notice that I use .. in the cd command. This tells the command to go up one directory level.
    The third line uses the for /f command to loop against the results of another command (in this case dir /ad /b, which translates into "give me a listing of directories (/ad) in bare format (/b)". %%g is a variable that holds one value at a time (the directory name). The output of that command looks something like this:

    Administrator
    Joe
    Bob
    Fred

    "do" tells the for statement which command to run against the results returned, in this case it's a simple copy command.

    ss64.com/nt has a pretty good guide on the for commands, as well as all the other command line commands.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: sequoya
  • You can also use the %allusersprofile% variable to copy the contents to the shared profile used by everyone ...

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Lmhansen
    You can also use the %allusersprofile% variable to copy the contents to the shared profile used by everyone ...


    I don't think that would work in this case. ...\local\... is not a default folder for any profile. Create a folder called "local" in c:\documents and settings\all users\local, then cd to your profile folder. Notice that there is no "local" folder.

    edit: to clarify, the application that's using the file has to be aware of the all user's profile.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: sequoya
  • Does Kaseya have an issue with copying xml files to a computer? I was able to copy the script to the computer, but the xml file that I need to copy does not.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rhollingsead
  • Any errors? Kaseya doesn't have problems copying XML files AFAIK.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: sequoya
  • No, no errors - in fact, Kaseya shows that the script ran successfully. But I've checked for the file anywhere on my computer, and all I get is the original file that I am trying to replace, same size, same modified date.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rhollingsead
  • rhollingsead
    No, no errors - in fact, Kaseya shows that the script ran successfully. But I've checked for the file anywhere on my computer, and all I get is the original file that I am trying to replace, same size, same modified date.


    Kaseya doesn't copy over files (I wish this were an option though!). You need to delete the file if it exists, then write the file to the machine.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: sequoya