在法语窗口上通过批处理脚本共享文件夹 [英] Sharing folder via batch script on french windows

查看:105
本文介绍了在法语窗口上通过批处理脚本共享文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的批处理脚本,用于与所有人"自动共享特定的文件夹.您可能已经注意到,我必须首先以当前安装的语言提取名称.对于法语版本,正确的字符串是"Tout le monde"(所有人).问题是我只得到"Tout"一词,而空格后的所有内容都将被忽略.

This is my batch script which I use to automatically share specific folder with "Everyone". As You might have noticed I have to first extract name in current installed language. For french version correct string is "Tout le monde" (Everyone). Problem is that I get only word "Tout" and everything after space is ignored.

 C:\WINDOWS\system32>net share SharedFolder="C:\Temp\SharedFolder" /GRANT:Tout,FULL

未共享结果文件夹.有人知道如何改进此脚本以获取所有空格的全名吗?

Result folder is not shared. Does anybody know how to improve this script in order to get full name with all spaces?

set MySid=S-1-1-0
for /f "delims= " %%a in ('"wmic path win32_account where SID='%MySid%' get name"') do (
   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

推荐答案

如果您显示了实际收到的wmic输出,将会很有帮助.根据我的英语版本,我建议

It would have been helpful if you'd shown the actual wmic output you are receiving. Based on my English-language version, I'd suggest

删除delims子句中="之间的空间.

Remove the space between the = and " in the delims clause.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION 
set MySid=S-1-1-0
for /f "delims=" %%a in ('"wmic path win32_account where SID='%MySid%' get name"') do (
 SET "line=%%a"
 CALL :striptrailing
 if not "!line!"=="Name" (
  set "myvar=!line!"
  goto :loop_end
 )
)
:loop_end

SET my
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

wmic输出线由CRCRLF终止,而不是常规的CRLF.因此,当delims为空时%%a的最后一个字符为CR-这使常规处理变得混乱.

The wmic output lines are terminated by CRCRLF, not CRLF as is convention. Consequently, the last character of %%a when delims is empty is CR - and this confuses conventional processing.

使用空格作为分隔符,%%a将在第一行获取Name-但这具有欺骗性,因为实际输出为Name [CR],因此delims正确选择了Name.

With Space as a delimiter, %%a will acquire Name on the first line - but that is deceptive as the actual output is Name [CR] hence delims correctly selects Name.

在下一行输出中,用英语显示Everyone [CR],再次正确"选择Everyone.如果用户为Atak Snajpera,则失败,因为用户只会选择Atak.

On the next output line, in English you get Everyone [CR] which again "correctly" selects Everyone. This would fail if the user was Atak Snajpera as it would select just Atak.

所以-我们需要关闭delims以获取整行,然后通过删除最后一个字符(将为CR)以及任何尾随空格来操纵line.这必须通过用户变量(我选择line)完成,因为在元变量上不允许使用子字符串.

So - we need to turn delims off to get the entire line, then manipulate line by removing the last character (which will be CR) and any trailing spaces. This must be done via a user-variable (I chose line) since substringing isn't allowed on metavariables.

为了访问代码块中uservariable的运行时值,您需要调用delayedexpansion.

In order to access the run-time value of the uservariable within the code-block, you need to invoke delayedexpansion.

:striptrailing例程无条件删除最后一个字符(我们知道它是一个CR),然后在line的最后一个字符为空格时继续执行.

The :striptrailing routine removes the last character unconditionally (we know it is a CR) and then continues while ever the last character of line is a space.

在审查代码时,我相信可以进行一些修改.

On reviewing the code, I believe it would be possible to make a couple of alterations.

首先,由于我们知道第一行将是Name,因此我们可以直接使用for中的skip=1访问第二行,这消除了对ifdelayedexpansion的需求. -我们要做的就是将例程移至loop_end之后以处理终端CR和空格.然后就不必使用line-可以使用myvar.

First, since we know the first line will be Name, we can access the second line directly using skip=1 in the for, which removes the requirement for the if and also for the delayedexpansion - all we need to do is move the routine to after loop_end to dispose of the terminal CR and spaces. And then there's no need to have line - myvar can be used instead.

我将作为练习留给那些感兴趣的人...

Which I'll leave as an exercise for those interested...

这篇关于在法语窗口上通过批处理脚本共享文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆