快捷方式凭据打开应用程序和资源管理器窗口

时间:2017-09-14 17:36:08

标签: powershell credentials powershell-v4.0

我正在尝试启动一个powershell脚本,该脚本请求我的密码以获取凭据的管理员帐户。拥有我的凭据后,它会打开一个PowerShell shell,启动一个Windows资源管理器窗口和一个应用程序,所有这些都带有管理员凭据。理想情况下,我也希望探索器窗口和shell打开到特定位置,但我没有尝试编码,直到我获得正确的凭据。

目前,每当我尝试以下代码时,我都会被告知用户名和密码不正确,因为我知道这是正确的用户名和密码。

package com.example.android.justtjava;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.awt.font.TextAttribute;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;


/**
 * This app displays an order form to order coffee.
 */
public class MainActivity extends AppCompatActivity {
    int quantity;
    String quantity1;
    boolean hasWhippedCream;
    boolean hasChocolate;
    String theName;
    int price;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /*Spinner coffeeSpinner = (Spinner) findViewById(R.id.spinner1);
        String quantity1 = coffeeSpinner.getSelectedItem().toString();
        Integer.parseInt(quantity1, quantity);
        ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.coffee_number_list));
        myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        coffeeSpinner.setAdapter(myAdapter);*/
    }

    public boolean dispatchTouchEvent(MotionEvent ev) {
        View v = getCurrentFocus();

        if (v != null &&
                (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) &&
                v instanceof EditText &&
                !v.getClass().getName().startsWith("android.webkit.")) {
            int scrcoords[] = new int[2];
            v.getLocationOnScreen(scrcoords);
            float x = ev.getRawX() + v.getLeft() - scrcoords[0];
            float y = ev.getRawY() + v.getTop() - scrcoords[1];

            if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom())
                hideKeyboard(this);
        }
        return super.dispatchTouchEvent(ev);
    }

    public static void hideKeyboard(Activity activity) {
        if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    private String createOrderSummary() {
        String priceMessage = getString(R.string.order_summary_name) + " " + theName;
        priceMessage = priceMessage + "\n" + getString(R.string.order_summary_whipped_cream) + " " + hasWhippedCream;
        priceMessage = priceMessage + "\n" + getString(R.string.order_summary_chocolate) + " " + hasChocolate;
        priceMessage = priceMessage + "\n" + getString(R.string.order_summary_quantity) + " " + quantity;
        priceMessage = priceMessage + "\n" + getString(R.string.order_summary_price) + " " + getString(R.string.Currency) + price;
        priceMessage += "\n" + getString(R.string.hb) + "\n" + getString(R.string.thank_you);
        return priceMessage;

    }

    /**
     * This method is called when the order button is clicked.
     */
    public void submitOrder(View view) {
        CheckBox r = findViewById(R.id.whipped_cream_check_box);
        hasWhippedCream = r.isChecked();
        EditText e = findViewById(R.id.editText2);
        theName = e.getText().toString();
        CheckBox c = findViewById(R.id.chocolate_checkbox);
        hasChocolate = c.isChecked();
        Log.v("MainActivity", "haswhippedcrm" + hasWhippedCream);
        int price = calculatePrice();
        String priceMessage = createOrderSummary();
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle this
        intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.order_summary_email_subject) + " " + theName);
        intent.putExtra(Intent.EXTRA_TEXT, priceMessage);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }
    }


    public void increment(View view) {

        if (quantity >= 100) {
            Context context = getApplicationContext();
            CharSequence text = "You can order a maximum of 100 coffees";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            return;
        } else {
            quantity = quantity + 1;
            displayQuantity(quantity);
        }

    }

    public void decrement(View view) {
        if (quantity <= 1) {
            Context context = getApplicationContext();
            CharSequence text = "You must order at least one coffee";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            return;
        } else {
            quantity = quantity - 1;
            displayQuantity(quantity);
        }

    }


//    *
//     * This method displays the given quantity value on the screen.

    private void displayQuantity(int digit) {
        TextView quantityTextView = findViewById(R.id.quantity_text_view);
        quantityTextView.setText("" + digit);


    }

   /* *
     * This method displays the given text on the screen.*/

    private void displayMessage(String message) {

        TextView order_summary_text_view = findViewById(R.id.price_text_view);

        order_summary_text_view.setText(message);

    }

    private int calculatePrice() {

        price = quantity * 5;
        if (hasWhippedCream == true && hasChocolate == true) {

            price = price + (quantity * 3);
        } else if (hasChocolate == true) {
            price = price + (quantity * 2);
        } else if (hasWhippedCream == true) {

            price = price + quantity;
        }
        return price;

    }
}

0 个答案:

没有答案