Sharing folder via batch script on french windows -


this batch script use automatically share specific folder "everyone". might have noticed have first extract name in current installed language. french version correct string "tout le monde" (everyone). problem word "tout" , after space ignored.

 c:\windows\system32>net share sharedfolder="c:\temp\sharedfolder" /grant:tout,full 

result folder not shared. know how improve script in order full name spaces?

set mysid=s-1-1-0 /f "delims= " %%a in ('"wmic path win32_account sid='%mysid%' name"') (    if not "%%a"=="name" (       set myvar=%%a       goto :loop_end    ) ) :loop_end  net share sharedfolder /delete /y net share sharedfolder="c:\temp\sharedfolder" /grant:%myvar%,full icacls "c:\temp\sharedfolder" /t /c /q /grant:r *%mysid%:(oi)(ci)f icacls "c:\temp\sharedfolder" /t /c /q /inheritance:e pause 

it have been helpful if you'd shown actual wmic output receiving. based on english-language version, i'd suggest

remove space between = , " in delims clause.

@echo off setlocal enabledelayedexpansion  set mysid=s-1-1-0 /f "delims=" %%a in ('"wmic path win32_account sid='%mysid%' name"') (  set "line=%%a"  call :striptrailing  if not "!line!"=="name" (   set "myvar=!line!"   goto :loop_end  ) ) :loop_end  set echo ==="%myvar%"---  goto :eof  :striptrailing if not defined line goto :eof  set "line=%line:~0,-1%" if not defined line goto :eof  if "%line:~-1%"==" " goto striptrailing goto :eof 

the wmic output lines terminated crcrlf, not crlf convention. consequently, last character of %%a when delims empty cr - , confuses conventional processing.

with space delimiter, %%a acquire name on first line - deceptive actual output name [cr] hence delims correctly selects name.

on next output line, in english everyone [cr] again "correctly" selects everyone. fail if user atak snajpera select atak.

so - need turn delims off entire line, manipulate line removing last character (which cr) and trailing spaces. must done via user-variable (i chose line) since substringing isn't allowed on metavariables.

in order access run-time value of uservariable within code-block, need invoke delayedexpansion.

the :striptrailing routine removes last character unconditionally (we know cr) , continues while ever last character of line space.

on reviewing code, believe possible make couple of alterations.

first, since know first line name, can access second line directly using skip=1 in for, removes requirement if , delayedexpansion - need move routine after loop_end dispose of terminal cr , spaces. , there's no need have line - myvar can used instead.

which i'll leave exercise interested...


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -