Please use the script to rename the computer if the computer even in domain
NewCompName = 'ComputerNoSpaceName' ## Enter your computer name with out any space to change the target computer
## Function to Execute CMD through Subprocess Module
def ExecuteCMD(CMD, OUT = False):
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
from subprocess import PIPE, Popen
with disable_file_system_redirection():
OBJ = Popen(CMD, shell = True, stdout = PIPE, stderr = PIPE)
out, err = OBJ.communicate()
RET = OBJ.returncode
if RET == 0:
if OUT == True:
if out != '':
return out.strip()
else:
return True
else:
return True
else:
return False
OldCompName = ExecuteCMD('hostname', True)
DisString = ''
##print ExecuteCMD('WMIC ComputerSystem where Name="'+OldCompName+'" call Rename Name="'+NewCompName+'"', True)
if ExecuteCMD('WMIC ComputerSystem where Name="'+OldCompName+'" call Rename Name="'+NewCompName+'"'):
DisString = 'Success: the Computer has been renamed as "'+NewCompName+'" from the old name "'+OldCompName+'"'
ExecuteCMD('shutdown -r -t 00')
if DisString:
print DisString
Sample Output:
Export Script Here,
20170124-Rename-the-Computer-Name.json (2.33 KB)