Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
Sars!

[NEED HELP] Command Prompt Program

Recommended Posts

Hey guys :)

It's been a while...

I would be happy if anyone could help.

I need a program in command prompt (a batch file I mean ofcourse), which does this:

Extract a registry file out of registry, and automatically upload it to an ftp server, in a map on the ftp server, which has the date as name.

This is what I got so far:

REG EXPORT HKEY_LOCAL_MACHINE\BLABLABLA C:\BLABLABLA.REG

ftp

open ftp.mysite.com

sars@mysite.com

mypassword

put c:\BLABLABLA.reg

bye

quit

Ofcourse it doesn't work, because the username and password aren't typed in manually. I don't think it is possible with the echo command, and it's definately not possible with the print command.

And how can you make a map on the ftp server with the current time, in which the reg file will be placed?

Any help appreciated.

Grtz,

SaRs!

EDIT:

I found those two which may help:

@echo off

echo.##################

echo.# #

echo.# Uploading File #

echo.# #

echo.##################

set user=YOUR_USERNAME_GOES_HERE

set pass=YOUR_PASS_GOES_HERE

set srvr=YOUR_SERVER_GOES_HERE

echo.open %srvr%>%temp%\sendtoftp.log

echo.%user%>>%temp%\sendtoftp.log

echo.%pass%>>%temp%\sendtoftp.log

echo.BINARY>>%temp%\sendtoftp.log

echo.put %1>>%temp%\sendtoftp.log

echo.bye>>%temp%\sendtoftp.log

ftp -s:%temp%\sendtoftp.log

del %temp%\sendtoftp.log

EDIT2:

Another problem I have are the spaces in the registry paths. How to write them in ur batch file?

Edited by Sars!

Share this post


Link to post
Share on other sites

How about something like this?

@echo off
setlocal

:: Create the date and time elements.
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set h1=%%m
set m1=%%n
set s1=%%o
)
)
Set PRE=%dd%-%mm%-%yy%

:: Export the key(s)
REG EXPORT HKLM\BLABLABLA %~dp0%PRE%_BLABLABLA.reg

:: Build the ftp command file
echo [UserName]> %~dp0send2ftp.txt
echo [Passwd]>> %~dp0send2ftp.txt
echo prompt n>>%~dp0send2ftp.txt
echo put %~dp0%PRE%_BLABLABLA.reg>> %~dp0send2ftp.txt
echo bye >> %~dp0send2ftp.txt

:: Send the file
ftp -s:%~dp0send2ftp.txt [ftp server]

:: Delete the command file
del %~dp0send2ftp.txt
endlocal

Share this post


Link to post
Share on other sites

What does this stand for:

%~dp0

Thanx a heaps,

SaRs!

EDIT: This is my current code:

@echo off

For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (

For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (

set dow=%%i

set %%a=%%j

set %%b=%%k

set %%c=%%l

set h1=%%m

set m1=%%n

set s1=%%o

)

)

Set PRE=%dd%-%mm%-%yy%

REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg C:\%~dp0%PRE%_systemlog.txt

@echo off

set user=...

set pass=...

set srvr=...

@echo off

echo.open %srvr%>>%temp%\sendtoftp.log

echo.%user%>>%temp%\sendtoftp.log

echo.%pass%>>%temp%\sendtoftp.log

echo.BINARY>>%temp%\sendtoftp.log

echo.put C:\%~dp0%PRE%_systemlog.txt>>%temp%\sendtoftp.log

echo.bye>>%temp%\sendtoftp.log

ftp -s:%temp%\sendtoftp.log

del %temp%\sendtoftp.log

The problem is that, if u open the .txt file after having downloaded it from the server, it displays a lot of strange chinese symbols. I tried both with Binary and not-binary sending. Both failed...

Any suggestions?

EDIT: And if two files are made on one day, one of them is overwritten. Maybe putting a time stamp on them too would help?

Thx a heaps for the help offered already,

SaRs!

Edited by Sars!

Share this post


Link to post
Share on other sites

I'd like to make a suggestion.

Try to use yyyy-mm-dd or at least yy-mm-dd it will help with standard sorting methods and follow the ISO 8601 standard format.

You dont want file 11-05-2006 to show before 16-03-2005 and 21-01-2007 for example!

Share this post


Link to post
Share on other sites

%~dp0 expands to the current directory, so C:\ in front of it is not needed. As for multiple files, just modify the time stamp with the time as needed since we already have the entire time defined. I picked up this snippet from WindowsITPro and it's explained in detail here. And Yzöwl's idea makes a lot of sense if you ever have to go back and sort through the data.

I didn't think about it before but the exported reg file is unicode, and your ftp server must be doing some kind of translation/conversion on it. But an extra step converting it to std ASCII solves the problem.

@echo off
setlocal
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set h1=%%m
set m1=%%n
set s1=%%o
)
)
:: Add the time to the stamp
Set PRE=%dd%-%mm%-%yy%_%hh%-%min%-%ss%
REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg %temp%\dump.reg
type %temp%\dump.reg>%~dp0%PRE%_systemlog.txt
del %temp%\dump.reg

set user=...
set pass=...
set srvr=...

echo open %srvr%>>%temp%\sendtoftp.log
echo %user%>>%temp%\sendtoftp.log
echo %pass%>>%temp%\sendtoftp.log
echo put %~dp0%PRE%_systemlog.txt>>%temp%\sendtoftp.log
echo bye>>%temp%\sendtoftp.log
ftp -s:%temp%\sendtoftp.log
del %temp%\sendtoftp.log
endlocal

I'd also recommend keeping the setlocal/endlocal lines so you don't keep the unnecessary variables around in the environment. Run your batch as is and then type 'set' at the command prompt to see what I mean.

Share this post


Link to post
Share on other sites
I didn't think about it before but the exported reg file is unicode, and your ftp server must be doing some kind of translation/conversion on it. But an extra step converting it to std ASCII solves the problem.

<snip>

REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg %temp%\dump.reg

type %temp%\dump.reg>%~dp0%PRE%_systemlog.txt

del %temp%\dump.reg

You can ignore all that if you use regedit to create the registry file in the first instance
REGEDIT/A %~dp0%PRE%_systemlog.txt HKEY_LOCAL_MACHINE\BABLA

Share this post


Link to post
Share on other sites

One more question:

What about spaces in the Registry path:

For example

HKEY_LOCAL_MACHINE\BLA BLA\BLABLABLA.reg

Now, when writing that into "" or even [] it doesn't work in command prompt.

Any help?

Grtz,

SaRs!

ps: U guys are like awesome :P

Share this post


Link to post
Share on other sites

If you are using my regedit example then the following should work exactly as expected.

REGEDIT/A %~dp0%PRE%_systemlog.txt "HKEY_LOCAL_MACHINE\BLA BLA\BLABLABLA"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...