0

This is the content of the conf file

use chroot = false

strict modes = false

hosts allow = *

log file = rsyncd.log

i need to add this two lines in the begin

uid=0

gid=0

and this other lines in the end

[data]

path = /cygdrive/d/My documents

read only = false

transfer logging = yes

[mail]

path = /cygdrive/d/mail

read only = false

transfer logging = yes

with the bat completed i will going to deploy it by policy on my network.

i´m really new in this, but i appreciate your help. Apologies for my english.

I tried with this code:

@echo off
Color 9A & Mode con cols=83 lines=5
Title %~n0 Adding lines to rsyncd.conf
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
REM  --> Check for permissions
Reg query "HKU\S-1-5-19\Environment" >nul 2>&1
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
Echo.
ECHO                      **************************************
ECHO                       Running Admin shell... Please wait...
ECHO                      **************************************
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B
:gotAdmin
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
set "hostspath=C:\Program Files (x86)\ICW\rsyncd.conf"
FIND /C /I "uid=0" "%hostspath%" >nul
FIND /C /I "gid=0" "%hostspath%" >nul
FIND /C /I "[data]" "%hostspath%" >nul
FIND /C /I "path = /cygdrive/d/My documents" "%hostspath%" >nul
FIND /C /I "read only = false" "%hostspath%" >nul
FIND /C /I "transfer logging = yes" "%hostspath%" >nul
FIND /C /I "[mail]" "%hostspath%" >nul
FIND /C /I "path = /cygdrive/d/mail" "%hostspath%" >nul
FIND /C /I "read only = false" "%hostspath%" >nul
FIND /C /I "transfer logging = yes" "%hostspath%" >nul
) 
Attrib +R "%hostspath%"

2 Answers2

0

You can use this script to get admin rights. Just copy the script to the end of a batch file with this script in the beginning:

@echo off

:: Run this script with elevation
call :RequestAdminElevation "%~dpfs0" %* || goto:eof

set "hostspath=C:\Program Files (x86)\ICW\rsyncd.conf"
set "new_hostspath=C:\Program Files (x86)\ICW\rsyncd.temp"

:: Add the first lines to the new file
echo uid=0> %new_hostspath%
echo gid=0>> %new_hostspath%

:: copy your original .conf file to the new one
type %hostspath% >> %new_hostspath%

:: add the last lines to the new file
echo [data] >> %new_hostspath%
echo path = /cygdrive/d/My documents >> %new_hostspath%
echo read only = false >> %new_hostspath%
echo transfer logging = yes >> %new_hostspath%
echo [mail] >> %new_hostspath%
echo path = /cygdrive/d/mail >> %new_hostspath%
echo read only = false >> %new_hostspath%
echo transfer logging = yes >> %new_hostspath%

:: copy new file over the old file
type %new_hostspath% > %hostspath

pause &goto:eof

[here you paste the RequestAdminElevation function code]
cyberponk
  • 1,585
  • 18
  • 19
0

All of the find commands are doing nothing - they simply check that the string is within the file and set errorlevel to 0 if found, non-0 if not - but having done the find you are doing nothing with the result.

::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
set "hostspath=C:\Program Files (x86)\ICW\rsyncd.conf"
FIND /C /I "uid=0" "%hostspath%" >nul
if not errorlevel 1 goto :eof
Attrib -R "%hostspath%"
(for %%a in ("gid=0" "uid=0") do echo %%~a)>tempfile.txt
type "%hostspath%" >>tempfile.txt
(for %%a in ("[data]"
 "uid=0"
"path = /cygdrive/d/My documents"
"read only = false"
"transfer logging = yes" 
"[mail]" 
"path = /cygdrive/d/mail"
"read only = false"
"transfer logging = yes"
 ) do echo %%~a
)>>tempfile.txt
move /y tempfile.txt "%hostspath%" 
Attrib +R "%hostspath%"

First, check whether uid=0 is in the file. If it is, assume the job has already been done and exit.

Remove the readonly flag from the .conf file

The for command will assign the "values in quotes" to %%a in turn, then echo each value (the ~ removes the enclosing quotes). The ( and ) enclosing the for command allow the output to be redirected to a file hich I named tempfile.txt.

Then type the contents of the existing .conf file to the tempfile

Then output the remaining lines, but this time the redirector is >> to append to tempfile.txt

Then move tempfile.txt over the .conf file and mark it readonly.

Magoo
  • 77,302
  • 8
  • 62
  • 84