mhammond / pywin32

Python for Windows (pywin32) Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Windows WBADMIN.EXE will run from win 10/11 but not Windows Server

paulkudla opened this issue Β· comments

See code below πŸ‘

works as is on win 11

but not Server 2019 which is based on win 10?

When i run on the server version I get πŸ‘


Starting Backup ....
C:\Windows\system32\wbadmin.exe
['wbadmin.exe', 'start', 'backup', '-backuptarget:\\10.0.0.2\images', '-include:C:', '-allcritical', '-quiet']
[b'wbadmin.exe', b'start', b'backup', b'-backuptarget:\\10.0.0.2\images', b'-include:C:', b'-allcritical', b'-quiet']

Traceback (most recent call last):
File "winbackup.py", line 201, in
wba_versions_process=subprocess.Popen(param_encode(wba_versions_args, locale.getdefaultlocale()[1] ), executable=wbadmin_bin, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\python3\lib\subprocess.py", line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\python3\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

F:\Programming\python\Windows Backup>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.


any help would be appreciated, more then happy to donate, probably a windows rights / permissions issue but cant figure it out ?

thanks

  • Version of Python and pywin32
    3.8.10 / pywin32-303

#!/usr/local/bin/python3
import os, sys, socket, struct, select, time
import logging, logging.handlers, traceback
import win32serviceutil
import servicemanager,win32evtlogutil,win32evtlog
import win32event,subprocess
import win32service,win32api,win32timezone
from multiprocessing import Process, freeze_support

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from email import encoders

import platform, locale

from optparse import OptionParser
USAGE_TEXT = '''
usage: %%prog %s[options]
'''

parser = OptionParser(usage=USAGE_TEXT % '', version='0.4')

parser.add_option("-m", "--mail", dest="mail_to", help="Email Report To", default = 'monitor@scom.ca')
parser.add_option("-d", "--destination", dest="destination", help="Destination Path")

options, args = parser.parse_args()

print (options.mail_to)
print (options.destination)

if options.destination == None :
print ('No Destination Provided')
print ('Exiting .....')
sys.exit()

#options.destination = options.destination.replace('\','\\' )

print (options.destination)

print ('Starting Backup ....')

def param_encode(lst, encoding, errors='strict'):
"""return a new encoded list of string"""
if isinstance(lst, list):
newlst=lst[:]
for i, v in enumerate(lst):
newlst[i]=v.encode(encoding, errors)
return newlst
elif isinstance(lst, unicode):
return lst.encode(encoding, errors)
else:
return lst

name='wbadmin'
exe='wbadmin.exe'
#C:\Windows\System32\WindowsPowerShell\v1.0

systemroot=os.environ.get('SystemRoot', os.environ.get('windir', 'C:\windows'))
wbadmin_bin=os.path.join(systemroot, 'system32', 'wbadmin.exe')
wevtutil_bin=os.path.join(systemroot, 'system32', 'wevtutil.exe')

print (wbadmin_bin)

#wba_versions_args=[ exe, 'get', 'versions', ]
wba_versions_args=[ exe, 'start', 'backup','-backuptarget:%s' %options.destination, '-include:C:', '-allcritical', '-quiet' ]

print (wba_versions_args)
print (param_encode(wba_versions_args, locale.getdefaultlocale()[1] ) )
print ()

wba_versions_process=subprocess.Popen(param_encode(wba_versions_args, locale.getdefaultlocale()[1] ), executable=wbadmin_bin, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
wba_versions_out, wba_versions_err=wba_versions_process.communicate()

wba_versions_out = str( wba_versions_out).split('\r\n')
wba_versions_err = str( wba_versions_err).split('\r\n')

out = ''
error = ''

for n in range (0,len(wba_versions_out)) :
print (wba_versions_out[n])
out = out + wba_versions_out[n] + '\n'

print ()
print ()

for n in range (0,len(wba_versions_err)) :
print (wba_versions_err[n])
error = error + wba_versions_err[n] + '\n'