Discussion:
how do I disjoin a machine to workgroup name
(too old to reply)
Joey
2009-05-04 22:22:00 UTC
Permalink
how do I modify the below to join a workgroup name "workgroup" instead of
the domain name?

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
unknown
2009-05-05 15:42:53 UTC
Permalink
First, is the computer currently a domain member, not a workgroup member? If
so - and only if so - you first need to use the UnjoinDomainOrWorkgroup the
way you have it.

The second step is to use JoinDomainOrWorkgroup, like this:

objComputer.JoinDomainOrWorkgroup("workgroup")


you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup" instead of
the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\"
& strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer &
"'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
Joey
2009-05-06 19:18:14 UTC
Permalink
ok

how do I add a line that will kill all processes ?

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")


Set OpSysSet = GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")

for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup member?
If so - and only if so - you first need to use the UnjoinDomainOrWorkgroup
the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup" instead of
the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &
"\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
unknown
2009-05-07 19:07:12 UTC
Permalink
Since you're using the Reboot() method, that will happen automatically. Are
you running into problems with making this work in a specific situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\"
& strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer &
"'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup member?
If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup" instead
of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &
"\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
Joey
2009-05-09 23:58:11 UTC
Permalink
yes after joining the domain, there isa process that keeps hanging and
waiting for a "end now". I want to be able to kill that process and then
reboot

"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Since you're using the Reboot() method, that will happen automatically.
Are you running into problems with making this work in a specific
situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &
"\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet =
GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup
member? If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup" instead
of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer
& "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
unknown
2009-05-10 20:56:39 UTC
Permalink
Instead of using Win32_OperatingSystem's Reboot() method, you're probably
better off using its Win32Shutdown; this allows you forced shutdown (trying
to kill all processes isn't going to work - it will kill your own script as
well, and some processes won't be touched).

You want to specify restart + forcing, which is a value of 6 if you check
the online documentation for the method:

http://msdn.microsoft.com/en-us/library/aa394058%28VS.85%29.aspx

so use it like this:
OpSys.Win32Shutdown( 6, 0)
Post by Joey
yes after joining the domain, there isa process that keeps hanging and
waiting for a "end now". I want to be able to kill that process and then
reboot
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Since you're using the Reboot() method, that will happen automatically.
Are you running into problems with making this work in a specific
situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &
"\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet =
GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup
member? If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup" instead
of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer
& "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
Joey
2009-05-11 17:59:02 UTC
Permalink
it says cannot use parenthesus when calling a Sub

"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Instead of using Win32_OperatingSystem's Reboot() method, you're probably
better off using its Win32Shutdown; this allows you forced shutdown
(trying to kill all processes isn't going to work - it will kill your own
script as well, and some processes won't be touched).
You want to specify restart + forcing, which is a value of 6 if you check
http://msdn.microsoft.com/en-us/library/aa394058%28VS.85%29.aspx
OpSys.Win32Shutdown( 6, 0)
Post by Joey
yes after joining the domain, there isa process that keeps hanging and
waiting for a "end now". I want to be able to kill that process and then
reboot
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Since you're using the Reboot() method, that will happen automatically.
Are you running into problems with making this work in a specific
situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer
& "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet =
GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup
member? If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup"
instead of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
unknown
2009-05-11 20:20:52 UTC
Permalink
Ah, you're not capturing the return value. Do so, and that fixes the
problem:

intRtn = OpSys.Win32Shutdown( 6, 0)

alternatively, if you don't want to check the return value, just don't use
the parentheses. VBScript has weird syntax requirements:

OpSys.Win32Shutdown 6, 0
Post by Joey
it says cannot use parenthesus when calling a Sub
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Instead of using Win32_OperatingSystem's Reboot() method, you're probably
better off using its Win32Shutdown; this allows you forced shutdown
(trying to kill all processes isn't going to work - it will kill your own
script as well, and some processes won't be touched).
You want to specify restart + forcing, which is a value of 6 if you check
http://msdn.microsoft.com/en-us/library/aa394058%28VS.85%29.aspx
OpSys.Win32Shutdown( 6, 0)
Post by Joey
yes after joining the domain, there isa process that keeps hanging and
waiting for a "end now". I want to be able to kill that process and then
reboot
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Since you're using the Reboot() method, that will happen automatically.
Are you running into problems with making this work in a specific
situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer
& "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet =
GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup
member? If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup"
instead of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
Joey
2009-05-12 18:05:57 UTC
Permalink
thank you very much
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Ah, you're not capturing the return value. Do so, and that fixes the
intRtn = OpSys.Win32Shutdown( 6, 0)
alternatively, if you don't want to check the return value, just don't use
OpSys.Win32Shutdown 6, 0
Post by Joey
it says cannot use parenthesus when calling a Sub
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknown
Instead of using Win32_OperatingSystem's Reboot() method, you're
probably better off using its Win32Shutdown; this allows you forced
shutdown (trying to kill all processes isn't going to work - it will
kill your own script as well, and some processes won't be touched).
You want to specify restart + forcing, which is a value of 6 if you
http://msdn.microsoft.com/en-us/library/aa394058%28VS.85%29.aspx
OpSys.Win32Shutdown( 6, 0)
Post by Joey
yes after joining the domain, there isa process that keeps hanging and
waiting for a "end now". I want to be able to kill that process and
then reboot
"Alex K. Angelopoulos" <alex(dot) k(dot
Post by unknown
Since you're using the Reboot() method, that will happen
automatically. Are you running into problems with making this work in
a specific situation?
Post by Joey
ok
how do I add a line that will kill all processes ?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
'strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
intReturn1 = objComputer.JoinDomainOrWorkgroup("workgroup")
Set OpSysSet =
GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
next
Post by unknown
First, is the computer currently a domain member, not a workgroup
member? If so - and only if so - you first need to use the
UnjoinDomainOrWorkgroup the way you have it.
objComputer.JoinDomainOrWorkgroup("workgroup")
you have the necessary privileges, don't bother with arguments
Post by Joey
how do I modify the below to join a workgroup name "workgroup"
instead of the domain name?
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" &
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
strDomain = objComputer.Domain
intReturn = objComputer.UnjoinDomainOrWorkgroup (NULL,NULL,0)
Loading...