脚本获取子网掩码和网关_如何将计算机的子网设置为用于登录脚本的系统变量。

脚本获取子网掩码和网关

Often times network admins need to run domain logon scripts for seperate subnets, but also for a seperate set of computers within that subnet.  In this circumstance, configuring Active Directory Sites and Services then linking a GPO to site/subnet might not be an option.

网络管理员通常需要为单独的子网运行域登录脚本,但也需要为该子网内的另一组计算机运行域登录脚本。 在这种情况下,可能无法选择配置Active Directory站点和服务,然后将GPO链接到站点/子网。

So now what ?

那么现在怎么办 ?

This is a real world example of this situation and my accepted solution: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Q_22746765.html?sfQueryTermInfo=1+locat+login+script+vb

这是这种情况和我接受的解决方案的真实示例: http://www.experts-exchang e.com/OS/M icrosoft_O perating_S 系统/服务 ver / Q_2274 6765.html? sfQueryTer mInfo = 1 + lo 猫+登录+ 脚本+ vb

This is the solution you can employ so that your logon scripts can identify the subnet a computer exists on...in order to decide whether to run or terminate.  Currently the script is only designed for class C network identification.

这是您可以采用的解决方案,以便您的登录脚本可以标识计算机所在的子网...以便决定运行还是终止。 当前,该脚本仅设计用于C类网络标识。

You need two things to make this work...

您需要两件事来使这项工作...

1) The attached vbscript (paste into notepad and save as *.vbs)

1)附加的vbscript(粘贴到记事本中并另存为* .vbs)

2) A program called setx.exe (Found in the MS Resource kit - http://www.microsoft.com/downloads/details.aspx?FamilyID=DC2D3339-8F36-4FBA-A406-2A2A2AD7208C&displaylang=en)

2)名为setx.exe的程序(位于MS Resource Kit中-http: //www.microsoft.com/d 自载/天 etails.asp x?FamilyID = DC2D3339- 8F36-4FBA- A406-2A2A2 AD7208C&di splaylang = zh

Once you have successfully employed this method....you can use the conditional code in your logon scripts using the subnet as a system variable.

成功使用此方法后,您可以使用子网作为系统变量在登录脚本中使用条件代码。

Example: The subnet is 192.168.6, which was set as a variable %IPNETID%, and I want a script to only run if that is the subnet the machine is presently on...

示例:子网是192.168.6,它已设置为变量%IPNETID%,并且我希望脚本仅在该计算机当前位于的子网中才能运行...

Therefore the first line on the logon batch script would be the following....

因此,登录批处理脚本的第一行将是以下内容。

IF NOT %IPNETID% == 192.168.6 EXIT

如果不是%IPNETID%== 192.168.6退出

or you could use this...

或者你可以使用这个...

IF %IPNETID% == 192.168.6 net use m: "\\server\share"

如果%IPNETID%== 192.168.6净使用m:“ \\服务器\共享”

This is my original solution which was published on Microsoft Script Center repository - Technet (http://www.microsoft.com/technet/scriptcenter/csc/scripts/desktop/settings/cscds060.mspx)

这是我的原始解决方案,已发布在Microsoft脚本中心存储库-Technet( http://www.microsoft.com/t echnet / scr iptcenter / csc /脚本 s /桌面/ 设置/ c scds060.ms px

Now when you move machines between subnets, the proper logon scripts will run automatically after the first reboot.

现在,当您在子网之间移动计算机时,正确的登录脚本将在第一次重新引导后自动运行。

NOTE: One caveat i've found, is that this script when used as a startup script will sometimes set the system variable only after the second reboot/logon, on a newly domain-joined machine.  I believe this is because of machine authentication reasons... not sure though.  Make sure the setx file is accessible to all machines, and that this script is set to run prior to other scripts running because the variable needs to be set prior to being used as a condition in your other logon scripts.

注意:我发现的一个警告是,此脚本用作启动脚本时,有时仅会在新加入域的计算机上第二次重新启动/登录后才设置系统变量。 我相信这是由于机器身份验证的原因...虽然不确定。 确保setx文件可被所有计算机访问,并且此脚本被设置为在其他脚本运行之前运行,因为在将其用作其他登录脚本中的条件之前,需要先设置变量。

翻译自: https://www.experts-exchange.com/articles/260/How-to-set-the-subnet-of-a-computer-to-a-system-variable-for-use-in-logon-scripts.html

脚本获取子网掩码和网关

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值