2
import os
import shutil


def listdirectory():
    global computername
    computername = input("What is the computer name? ")
    completepathlist = fr"\\{computername}\C$\Users"
    return os.listdir(completepathlist)

def username():
    global completepath
    global usernameinput
    usernameinput = input("What is the user name? ")
    completepath = fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"

def programrunningcheck():
    password = input("What is your password? ")
    command = "taskkill /s " + str(computername) + " /u " + str(usernameinput) + " /p " +password+ " /im chrome.exe"
    print(command)
    os.system(command)

def deletegoogleapp():
    shutil.rmtree(completepath)

#Functions being called
print(listdirectory())
username()
programrunningcheck()
deletegoogleapp()

Everything works up until deletegoogleapp function is called and receive a

\\DESKTOP-62A8SSM\C$\Users\"function username at 0x010C8B28\AppData\Local\Google

looks to be not passing the variable completepath from another function to the googleapp function.

nick
  • 1,090
  • 1
  • 11
  • 24
Jason Lucas
  • 113
  • 9
  • my suggestion would be that you rewrite what you have done without all these functions, when that is working you can wrap that into a single function call. if you need every variable to be global, do you really need functions in the way you have attempted to use them? – ahed87 Jan 12 '19 at 16:22
  • I agree may not be best written - I'm new to programing and self teaching so I am sure I have a lot of bad practice's – Jason Lucas Jan 12 '19 at 16:46
  • The `username` variable used by `fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"` is the name of the **function** the statement is in — i.e. `function username at 0x010C8B28`. I think you want `usernameinput`. – martineau Jan 12 '19 at 17:01
  • You could either use global variables: https://stackoverflow.com/a/423596/6212957 OR you could pass previous function as a parameter to get it's return value `lastfunction( secondfunction() )` – Feelsbadman Jan 12 '19 at 17:06
  • ahed87 - would love to see another example of writing this in one function - I would love to learn – Jason Lucas Jan 12 '19 at 17:53

3 Answers3

0

You need so store the return value of username, right now, you are passing nothing to deletegoogleapp. So you can do:

u <- username()
programrunningcheck()
deletegoogleapp(u)

This should work given the path u returned is valid.

YOLO
  • 20,181
  • 5
  • 20
  • 40
0

change you'r function username:

global completepath
global usernameinput

def username(self):
    usernameinput = input("What is the user name? ")
    completepath = fr"\\{computername}\C$\Users\{username}\AppData\Local\Google"
magic man
  • 1
  • 3
0

Fixed original issue with var and made some other coding change

import os
import shutil
import time


def listdirectory():
    global computername
    computername = input("What is the computer name? ")
    completepathlist = fr"\\{computername}\C$\Users"
    return os.listdir(completepathlist)

def username():
    global completepath
    usernameinput = input("What is the user name? ")
    completepath = fr"\\{computername}\C$\Users\{usernameinput}\AppData\Local\Google"

def programrunningcheck():
    print("We need your credentials to kill chrome")
    techuser = input("What is your username? ")
    techpassword = input("What is your password? ")
    command = "taskkill /s " + str(computername) + " /u " + str(techuser) + " /p " +(techpassword)+ " /im chrome.exe"
    time.sleep(5)
    print(command)
    os.system(command)

def deletegoogleapp():
    shutil.rmtree(completepath)

#Functions being called
print(listdirectory())
username()
programrunningcheck()
deletegoogleapp()
Jason Lucas
  • 113
  • 9
  • Can you [edit] this and add how it solved your problem? That will help others with a similar problem. – Jongware Jan 13 '19 at 13:06
  • Fixes were my variable for username did not match my string name for username - bigger issue was it was passing the inputed username to taskkill - now prompts for separate account that has remote admin rights to kill task on that pc – Jason Lucas Jan 13 '19 at 13:22