Solved

Script to copy file to Randomly generated Directory

Posted on 2012-04-05
11
593 Views
Last Modified: 2012-04-06
I am trying to create a script to copy a file from one directory to another directory that is randomly named by Firefox. The folder is a profile directory and it's different for every installation. As you can see below the random characters are just before the '.default' string. I tried using a wild card but it didn't work.

%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\

This is what I attempted without any luck:

xcopy \\domain\netlogon\file.txt  %USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default

Any help would be appreciated.
0
Comment
Question by:swhitti
  • 6
  • 5
11 Comments
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37814715
Here's a BAT file that should do the job:
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do xcopy "\\domain\netlogon\file.txt" "%%~A"

Open in new window

~bp
0
 

Author Comment

by:swhitti
ID: 37816527
That was perfect! Thanks so much for the help. I will be giving you the full points.

It turns out that I also have to append a line,

user_pref("extensions.blocklist.url", "127.0.0.1");

to a specific file called pref.js in that same random generated directory.

If adding this to a current request is not acceptable please let me know and I will be happy to open another question.

Thanks again!
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37816655
Give this a try, I think it should do what you described.
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\file.txt" "%%~A"
  echo user_pref("extensions.blocklist.url", "127.0.0.1"); >>"%%~A\pref.js"
)

Open in new window

~bp
0
 

Author Comment

by:swhitti
ID: 37816712
Thanks for continuing to help me.

It copied the line I needed but included some additional info also, this is what was appended:

\\domain\netlogon\file.txt
1 File(s) copied
user_pref("extensions.blocklist.url", "127.0.0.1"
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37817339
Can you post up the script you ran please.

~bp
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:swhitti
ID: 37817519
It is basically the same script you supplied me with a few changes to the domain and file name.

@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\blocklist.xml" "%%~A"
  echo user_pref("extensions.blocklist.url", "127.0.0.1"); >>"%%~A\prefs.js"
)

In the pref.js file it appends this to the bottom of the file:

\\domain\netlogon\file.txt
1 File(s) copied
user_pref("extensions.blocklist.url", "127.0.0.1"

I don't need the line about the file path or the '1 File(s) copied' and it is missing the closed bracket and semicolon, ie. );

or

user_pref("extensions.blocklist.url", "127.0.0.1");
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37817527
Interesting, let me play with that, I suspect it's the parenthesis after the 127.0.0.1 that is an issue, we should be able to work around that.

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37817565
Okay, try this, it should work.
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\blocklist.xml" "%%~A"
  echo user_pref^("extensions.blocklist.url", "127.0.0.1"^); >>"%%~A\prefs.js"
)

Open in new window

~bp
0
 

Author Comment

by:swhitti
ID: 37817588
You're AMAZING! I can't thank you enough for working on this for me. That worked perfectly. If there is any way of giving you more points let me know and I would be happy to do so. :)

Have a great weekend...
0
 

Author Comment

by:swhitti
ID: 37817667
I have one more requirement which I will open a new question for as I want you to be able to answer and get points for, if you feel inclined. Please keep an eye out for it.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 37817915
Sorry, was away from the computer for a while so missed that until just now, but glad you got some help with it.

~bp
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now