I am trying to create a FAST API to change the name of the system by executing the bat files. The name gets changed but its not accepting special characters like -
, ,
and '
.
I have searched a lot but didn't get any solution for it. I have tried executing the PowerShell command but it asks for admin access.
Here is my bat file code:
@ECHO OFF
### For Admin Previleges
set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
set arg1=%1
set arg2=%2
wmic computersystem where caption='%arg1%' rename '%arg2%'
move nul 2>&0
Here is my python code for executing batch files:
def set_Computer_Name(computer_name : str):
current_computer_name = platform.node()
process = subprocess.run(['computer_name.bat', current_computer_name, computer_name])
return {"status" : process.returncode}
How can I fix this?